#Region "Form Comments"

' AUTHOR: Evan X. Merz
' Contributing Programmer: Andre Knight
' DATE: 08/21/2008
' CLASS: frmWiiDrums
' PURPOSE: This class interprets wiimote gestures and triggers sound files
' Please don't email me about bugs.  I know there are bugs.
' HOWEVER, do email me if you make any improvements, and I will add the improvements to the main version, with credit given.

' LICENSE: This can be used in any way you see fit, as long as you credit the author appropriately.
' For instance, in the credits, you might put "wiimote code based on code by Evan X. Merz" or something ...  
' if you do that, please shoot me an email and let me know: evan at thisisnotalabel dot com

' If you make changes, comment them with your name, so we can ctrl+f for them

#End Region

#Region "Change Log"

'***********************************************************************************************
' CHANGE LOG
' ----------------------------------------------------------------------------------------------
' ----------------------------------------------------------------------------------------------
' Date      Name                Description
' ----------------------------------------------------------------------------------------------
' Jan. 08   Evan Merz           Opened this code to all
' ----------------------------------------------------------------------------------------------
' Feb. 23 - August 21   Andre Knight        
'                               Re-designed Main Form GUI
'                               Added Wiimote Test Connection Form And Code
'                               Added Many New Project Resources - .wav files, images
'                               Reworked Preset File Code
'                               Added Recording Functionality Using DirectX
'                               Added More Wiimote Gesture + Buttons Combinations
'                               Added Support For 2 Wiimotes
'                               Added About Form
'                               Created New Setup Project
' ----------------------------------------------------------------------------------------------
'
'***********************************************************************************************

#End Region

#Region "Imports"

Imports System
Imports System.Drawing
Imports System.IO
Imports System.Threading
Imports Microsoft.DirectX
Imports Microsoft.DirectX.DirectSound
Imports Microsoft.VisualBasic.Devices
Imports WiimoteLib

#End Region

Public Class frmWiiDrums

#Region "Form Globals"

    'Container that holds wiimote objects
    Private m_wiimotecollection As WiimoteCollection

    'Instantiate New Wiimote Objects with events
    Private WithEvents wiimote1 As New Wiimote()
    Private WithEvents wiimote2 As New Wiimote()

    Public Property Wiimote_Collection() As WiimoteCollection
        Get
            Return m_wiimotecollection
        End Get
        Set(ByVal value As WiimoteCollection)
            m_wiimotecollection = value
        End Set
    End Property

    'Private Data Member To Hold StartUp Form
    Private m_FormTestConnection As frmTestConnection

    Public Property FormTestConnection() As frmTestConnection
        Get
            Return m_FormTestConnection
        End Get
        Set(ByVal value As frmTestConnection)
            m_FormTestConnection = value
        End Set
    End Property

    Private FormMetronome As frmMetronome = Nothing

    'Delegates Used To Set Control.Text On A Different Thread
    Delegate Sub SetText(ByRef pLabel As Label, ByVal text As String)
    Delegate Sub SetInt(ByRef pProgessBar As ProgressBar, ByVal value As Integer)

    'Math stuff  for wiimote1
    Private x1 As Double
    Private y1 As Double
    Private z1 As Double
    Private nunchuk1 As Double
    Private xMinThresh1 As Double
    Private yMinThresh1 As Double
    Private zMaxThresh1 As Double
    Private nunchukThresh1 As Double

    'Math stuff  for wiimote2
    Private x2 As Double
    Private y2 As Double
    Private z2 As Double
    Private nunchuk2 As Double
    Private xMinThresh2 As Double
    Private yMinThresh2 As Double
    Private zMaxThresh2 As Double
    Private nunchukThresh2 As Double

    'Buffers for wiimote1
    Private wiimoteDownTriggerBuffer1 As Integer = 0
    Private wiimoteLeftTriggerBuffer1 As Integer = 0
    Private wiimoteForwardTriggerBuffer1 As Integer = 0
    Private nunchukTriggerBuffer1 As Integer = 0
    Private Const BUFFERRESETVALUE1 As Integer = 6

    'Buffers for wiimote2
    Private wiimoteDownTriggerBuffer2 As Integer = 0
    Private wiimoteRightTriggerBuffer2 As Integer = 0
    Private wiimoteForwardTriggerBuffer2 As Integer = 0
    Private nunchukTriggerBuffer2 As Integer = 0
    Private Const BUFFERRESETVALUE2 As Integer = 6

    'Integers representing the indexes of wiimote1 sound files within soundbank
    Private SoundLeftRight1 As Integer
    Private SoundLeftRightWithA1 As Integer
    Private SoundDown1 As Integer
    Private SoundNunchuk1 As Integer
    Private SoundNunchukWithC1 As Integer
    Private SoundNunchukWithZ1 As Integer
    Private SoundForwardAndDown1 As Integer
    Private SoundForwardAndDownWithA1 As Integer
    Private SoundForwardAndDownWithB1 As Integer
    Private SoundForwardAndDownWithLeft1 As Integer
    Private SoundForwardAndDownWithRight1 As Integer
    Private SoundForwardAndDownWithUp1 As Integer
    Private SoundForwardAndDownWithDown1 As Integer
    Private SoundForwardAndDownWithMinus1 As Integer
    Private SoundForwardAndDownWithHome1 As Integer
    Private SoundForwardAndDownWithPlus1 As Integer

    'Integers representing the indexes of wiimote2 sound files within soundbank
    Private SoundLeftRight2 As Integer
    Private SoundLeftRightWithA2 As Integer
    Private SoundDown2 As Integer
    Private SoundNunchuk2 As Integer
    Private SoundNunchukWithC2 As Integer
    Private SoundNunchukWithZ2 As Integer
    Private SoundForwardAndDown2 As Integer
    Private SoundForwardAndDownWithA2 As Integer
    Private SoundForwardAndDownWithB2 As Integer
    Private SoundForwardAndDownWithLeft2 As Integer
    Private SoundForwardAndDownWithRight2 As Integer
    Private SoundForwardAndDownWithUp2 As Integer
    Private SoundForwardAndDownWithDown2 As Integer
    Private SoundForwardAndDownWithMinus2 As Integer
    Private SoundForwardAndDownWithHome2 As Integer
    Private SoundForwardAndDownWithPlus2 As Integer

    'Play Audio Class And Also Where The .WAV File Names Are Stored
    Private soundbank As SoundBank

    'Record Devices Variables
    Dim devices As New CaptureDevicesCollection()
    Private CaptureDeviceGuid As Guid = Guid.Empty 'Need To Set To Parameter in Record Sound Constructor

    'Formats Variables - DirectX Sound Recording
    Public CaptureBufferSize As Integer = 0 'Need To Set To Parameter in Record Sound Constructor
    Public NotifySize As Integer = 0 'Need To Set To Parameter in Record Sound Constructor
    Private formats As New ArrayList()
    Private InputFormatSupported As Boolean() = New Boolean(19) {}
    Public InputFormat As WaveFormat  'Need To Set To Parameter in Record Sound Constructor
    Public applicationDevice As Capture = Nothing 'Need To Set To Parameter In Record Sound Constructor
    Private Recording As Boolean = False 'Need To Set To Parameter In Record Sound Constructor
    Private Path As String = String.Empty 'Need To Set To Parameter In Record Sound Constructor
    Private FileName As String = String.Empty 'Need To Set To Parameter In Record Sound Constructor
    Private Writer As BinaryWriter = Nothing 'Need To Set To Parameter In Record Sound Constructor
    Private WaveFile As FileStream = Nothing 'Need To Set To Parameter In Record Sound Constructor
    Public applicationBuffer As CaptureBuffer = Nothing
    Public applicationNotify As Notify = Nothing
    Public PositionNotify As BufferPositionNotify() = New BufferPositionNotify(NumberRecordNotifications + 1) {}
    Public Const NumberRecordNotifications As Integer = 16
    Public NotificationEvent As AutoResetEvent = Nothing
    Private NotifyThread As Thread = Nothing
    Public NextCaptureOffset As Integer = 0
    Private SampleCount As Integer = 0
    Private Capturing As Boolean = False

    ' tooltip object
    Private tt As ToolTip

    Dim SelectedDirectoryPath As String = String.Empty

    Private Fade As Integer = 0

    Private imageswitch As Integer = 0

#End Region

#Region "Wiimote Code"

    'When the wiimote 1 state changes
    Private Sub wiimote1_WiimoteChanged(ByVal sender As Object, ByVal args As WiimoteLib.WiimoteChangedEventArgs) Handles wiimote1.WiimoteChanged

        Dim wiimote1state As WiimoteState = args.WiimoteState

        ' decrement each timing buffer
        If wiimoteDownTriggerBuffer1 > -1 Then wiimoteDownTriggerBuffer1 = wiimoteDownTriggerBuffer1 - 1
        If wiimoteLeftTriggerBuffer1 > -1 Then wiimoteLeftTriggerBuffer1 = wiimoteLeftTriggerBuffer1 - 1
        If wiimoteForwardTriggerBuffer1 > -1 Then wiimoteForwardTriggerBuffer1 = wiimoteForwardTriggerBuffer1 - 1
        If nunchukTriggerBuffer1 > -1 Then nunchukTriggerBuffer1 = nunchukTriggerBuffer1 - 1

        'BatteryLevel
        If wiimote1state.Battery > &HC8 Then
            Me.SetProgressBarValue(pbWiimote1Battery, (&HC8))
            'pbWiimote1Battery.Value = (&HC8)
        Else
            Dim tempvalue As Integer = ((CInt(Fix(wiimote1state.Battery))))
            Me.SetProgressBarValue(pbWiimote1Battery, tempvalue)
            'pbWiimote1Battery.Value = (CInt(Fix(wiimote1state.Battery)))
        End If
        Dim f As Single = (((100.0F * 48.0F * CSng(wiimote1state.Battery / 48.0F))) / 192.0F)
        'lblWiimote1Battery.Text = f.ToString("F") & " %"
        Me.SetLabelText(lblWiimote1Battery, f.ToString("F") & " %")


        ' If The Wiimote Is Tilted Left
        If wiimoteLeftTriggerBuffer1 < 0 Then

            x1 = CDbl(wiimote1state.AccelState.Values.X)

            If chk1MotionLeftRight.Checked = True And x1 < xMinThresh1 Then
                If wiimote1state.ButtonState.A Then ' if A is being pressed
                    If chk1MotionLeftRightRetrigger.Checked Then soundbank.stopSound(SoundLeftRightWithA1)
                    soundbank.startSound(SoundLeftRightWithA1)
                    wiimoteLeftTriggerBuffer1 = BUFFERRESETVALUE1
                    wiimoteForwardTriggerBuffer1 = BUFFERRESETVALUE1
                    Exit Sub
                Else
                    If chk1MotionLeftRightRetrigger.Checked Then soundbank.stopSound(SoundLeftRight1)
                    soundbank.startSound(SoundLeftRight1)
                    wiimoteLeftTriggerBuffer1 = BUFFERRESETVALUE1
                    wiimoteForwardTriggerBuffer1 = BUFFERRESETVALUE1
                    Exit Sub
                End If
            End If
        End If

        'If the wiimote rotates forward and down
        If wiimoteForwardTriggerBuffer1 < 0 Then

            z1 = CDbl(wiimote1state.AccelState.Values.Z)

            If chk1MotionForwardAndDown.Checked = True And z1 > zMaxThresh1 Then

                If wiimote1state.ButtonState.A Then ' if A is held
                    If chk1MotionForwardDownRetrigger.Checked = True Then soundbank.stopSound(SoundForwardAndDownWithA1)
                    soundbank.startSound(SoundForwardAndDownWithA1)
                    wiimoteForwardTriggerBuffer1 = BUFFERRESETVALUE1
                    Exit Sub

                ElseIf wiimote1state.ButtonState.B Then 'If B is held
                    If chk1MotionForwardDownRetrigger.Checked = True Then soundbank.stopSound(SoundForwardAndDownWithB1)
                    soundbank.startSound(SoundForwardAndDownWithB1)
                    wiimoteForwardTriggerBuffer1 = BUFFERRESETVALUE1
                    Exit Sub

                ElseIf wiimote1state.ButtonState.Left Then 'If D-Pad Left is held
                    If chk1MotionForwardDownRetrigger.Checked = True Then soundbank.stopSound(SoundForwardAndDownWithLeft1)
                    soundbank.startSound(SoundForwardAndDownWithLeft1)
                    wiimoteForwardTriggerBuffer1 = BUFFERRESETVALUE1
                    Exit Sub

                ElseIf wiimote1state.ButtonState.Right Then 'If D-Pad Right is held
                    If chk1MotionForwardDownRetrigger.Checked = True Then soundbank.stopSound(SoundForwardAndDownWithRight1)
                    soundbank.startSound(SoundForwardAndDownWithRight1)
                    wiimoteForwardTriggerBuffer1 = BUFFERRESETVALUE1
                    Exit Sub

                ElseIf wiimote1state.ButtonState.Up Then 'If D-Pad Up is held
                    If chk1MotionForwardDownRetrigger.Checked = True Then soundbank.stopSound(SoundForwardAndDownWithUp1)
                    soundbank.startSound(SoundForwardAndDownWithUp1)
                    wiimoteForwardTriggerBuffer1 = BUFFERRESETVALUE1
                    Exit Sub

                ElseIf wiimote1state.ButtonState.Down Then 'If D-Pad Down is held
                    If chk1MotionForwardDownRetrigger.Checked = True Then soundbank.stopSound(SoundForwardAndDownWithDown1)
                    soundbank.startSound(SoundForwardAndDownWithDown1)
                    wiimoteForwardTriggerBuffer1 = BUFFERRESETVALUE1
                    Exit Sub

                ElseIf wiimote1state.ButtonState.Minus Then 'If Minus is held
                    If chk1MotionForwardDownRetrigger.Checked = True Then soundbank.stopSound(SoundForwardAndDownWithMinus1)
                    soundbank.startSound(SoundForwardAndDownWithMinus1)
                    wiimoteForwardTriggerBuffer1 = BUFFERRESETVALUE1
                    Exit Sub

                ElseIf wiimote1state.ButtonState.Home Then 'If Home is held
                    If chk1MotionForwardDownRetrigger.Checked = True Then soundbank.stopSound(SoundForwardAndDownWithHome1)
                    soundbank.startSound(SoundForwardAndDownWithHome1)
                    wiimoteForwardTriggerBuffer1 = BUFFERRESETVALUE1
                    Exit Sub

                ElseIf wiimote1state.ButtonState.Plus Then 'If Plus is held
                    If chk1MotionForwardDownRetrigger.Checked = True Then soundbank.stopSound(SoundForwardAndDownWithPlus1)
                    soundbank.startSound(SoundForwardAndDownWithPlus1)
                    wiimoteForwardTriggerBuffer1 = BUFFERRESETVALUE1
                    Exit Sub

                Else
                    If chk1MotionForwardDownRetrigger.Checked = True Then soundbank.stopSound(SoundForwardAndDown1)
                    soundbank.startSound(SoundForwardAndDown1)
                    wiimoteForwardTriggerBuffer1 = BUFFERRESETVALUE1
                    wiimoteLeftTriggerBuffer1 = BUFFERRESETVALUE1
                    Exit Sub

                End If

            End If

        End If

        'If the wiimote moves down
        If wiimoteDownTriggerBuffer1 < 0 Then

            y1 = CDbl(wiimote1state.AccelState.Values.Y)

            If chk1MotionDown.Checked And y1 < yMinThresh1 Then
                If chk1MotionDownRetrigger.Checked = True Then soundbank.stopSound(SoundDown1)
                soundbank.startSound(SoundDown1)
                wiimoteDownTriggerBuffer1 = BUFFERRESETVALUE1
                Exit Sub
            End If

        End If

        'Nunchuk
        If nunchukTriggerBuffer1 < 0 And chk1MotionNunchuk.Checked And wiimote1.WiimoteState.ExtensionType = ExtensionType.Nunchuk Then

            nunchuk1 = CDbl(wiimote1.WiimoteState.NunchukState.AccelState.Values.Y)

            'If The Nunchuk Moves Down And C Is Pressed
            If nunchuk1 > nunchukThresh1 And wiimote1.WiimoteState.NunchukState.C Then
                If chk1NunchukRetrigger.Checked Then
                    soundbank.stopSound(SoundNunchukWithC1)
                End If
                soundbank.startSound(SoundNunchukWithC1)
                nunchukTriggerBuffer1 = BUFFERRESETVALUE1
                Exit Sub

                'If The Nunchuk Moves Down And C Is Pressed
            ElseIf nunchuk1 > nunchukThresh1 And wiimote1.WiimoteState.NunchukState.Z Then
                If chk1NunchukRetrigger.Checked Then
                    soundbank.stopSound(SoundNunchukWithZ1)
                End If
                soundbank.startSound(SoundNunchukWithZ1)
                nunchukTriggerBuffer1 = BUFFERRESETVALUE1
                Exit Sub

                'If the nunchuk moves down and no buttons are pressed
            Else
                If nunchuk1 > nunchukThresh1 Then
                    If chk1NunchukRetrigger.Checked Then
                        soundbank.stopSound(SoundNunchuk1)
                    End If
                    soundbank.startSound(SoundNunchuk1)
                    nunchukTriggerBuffer1 = BUFFERRESETVALUE1
                    Exit Sub
                End If

            End If

        End If

    End Sub

    'When the wiimote 2 state changes
    Private Sub wiimote2_WiimoteChanged(ByVal sender As Object, ByVal args As WiimoteLib.WiimoteChangedEventArgs) Handles wiimote2.WiimoteChanged

        Dim wiimote2state As WiimoteState = args.WiimoteState

        ' decrement each timing buffer
        If wiimoteDownTriggerBuffer2 > -1 Then wiimoteDownTriggerBuffer2 = wiimoteDownTriggerBuffer2 - 1
        If wiimoteRightTriggerBuffer2 > -1 Then wiimoteRightTriggerBuffer2 = wiimoteRightTriggerBuffer2 - 1
        If wiimoteForwardTriggerBuffer2 > -1 Then wiimoteForwardTriggerBuffer2 = wiimoteForwardTriggerBuffer2 - 1
        If nunchukTriggerBuffer2 > -1 Then nunchukTriggerBuffer2 = nunchukTriggerBuffer2 - 1

        'BatteryLevel
        If wiimote2state.Battery > &HC8 Then
            Me.SetProgressBarValue(pbWiimote1Battery, (&HC8))
            'pbWiimote2Battery.Value = (&HC8)
        Else
            Dim tempvalue As Integer = ((CInt(Fix(wiimote2state.Battery))))
            Me.SetProgressBarValue(pbWiimote2Battery, tempvalue)
            'pbWiimote2Battery.Value = (CInt(Fix(wiimote2state.Battery)))
        End If
        Dim f As Single = (((100.0F * 48.0F * CSng(wiimote2state.Battery / 48.0F))) / 192.0F)
        Me.SetLabelText(lblWiimote2Battery, f.ToString("F") & " %")
        ' lblWiimote2Battery.Text = f.ToString("F") & " %"

        ' if the wiimote tilts Right
        If wiimoteRightTriggerBuffer2 < 0 Then

            x2 = CDbl(wiimote2state.AccelState.Values.X)

            If chk2MotionLeftRight.Checked = True And x2 > xMinThresh2 Then
                If wiimote2state.ButtonState.A Then ' if A is being pressed
                    If chk2MotionLeftRightRetrigger.Checked = True Then soundbank.stopSound(SoundLeftRightWithA2)
                    soundbank.startSound(SoundLeftRightWithA2)
                    wiimoteRightTriggerBuffer2 = BUFFERRESETVALUE2
                    wiimoteForwardTriggerBuffer2 = BUFFERRESETVALUE2
                    Exit Sub
                Else
                    If chk2MotionLeftRightRetrigger.Checked = True Then soundbank.stopSound(SoundLeftRight2)
                    soundbank.startSound(SoundLeftRight2)
                    wiimoteRightTriggerBuffer2 = BUFFERRESETVALUE2
                    wiimoteForwardTriggerBuffer2 = BUFFERRESETVALUE2
                    Exit Sub
                End If
            End If
        End If

        'If the wiimote rotates forward and down
        If wiimoteForwardTriggerBuffer2 < 0 Then

            z2 = CDbl(wiimote2state.AccelState.Values.Z)

            If chk2MotionForwardDown.Checked = True And z2 > zMaxThresh2 Then

                If wiimote2state.ButtonState.A Then ' if A is held
                    If chk2MotionForwardDownRetrigger.Checked = True Then soundbank.stopSound(SoundForwardAndDownWithA2)
                    soundbank.startSound(SoundForwardAndDownWithA2)
                    wiimoteForwardTriggerBuffer2 = BUFFERRESETVALUE2
                    Exit Sub

                ElseIf wiimote2state.ButtonState.B Then 'If B is held
                    If chk2MotionForwardDownRetrigger.Checked = True Then soundbank.stopSound(SoundForwardAndDownWithB2)
                    soundbank.startSound(SoundForwardAndDownWithB2)
                    wiimoteForwardTriggerBuffer2 = BUFFERRESETVALUE2
                    Exit Sub

                ElseIf wiimote2state.ButtonState.Left Then 'If D-Pad Left is held
                    If chk2MotionForwardDownRetrigger.Checked = True Then soundbank.stopSound(SoundForwardAndDownWithLeft2)
                    soundbank.startSound(SoundForwardAndDownWithLeft2)
                    wiimoteForwardTriggerBuffer2 = BUFFERRESETVALUE2
                    Exit Sub

                ElseIf wiimote2state.ButtonState.Right Then 'If D-Pad Right is held
                    If chk2MotionForwardDownRetrigger.Checked = True Then soundbank.stopSound(SoundForwardAndDownWithRight2)
                    soundbank.startSound(SoundForwardAndDownWithRight2)
                    wiimoteForwardTriggerBuffer2 = BUFFERRESETVALUE2
                    Exit Sub

                ElseIf wiimote2state.ButtonState.Up Then 'If D-Pad Up is held
                    If chk2MotionForwardDownRetrigger.Checked = True Then soundbank.stopSound(SoundForwardAndDownWithUp2)
                    soundbank.startSound(SoundForwardAndDownWithUp2)
                    wiimoteForwardTriggerBuffer2 = BUFFERRESETVALUE2
                    Exit Sub

                ElseIf wiimote2state.ButtonState.Down Then 'If D-Pad Down is held
                    If chk2MotionForwardDownRetrigger.Checked = True Then soundbank.stopSound(SoundForwardAndDownWithDown2)
                    soundbank.startSound(SoundForwardAndDownWithDown2)
                    wiimoteForwardTriggerBuffer2 = BUFFERRESETVALUE2
                    Exit Sub

                ElseIf wiimote2state.ButtonState.Minus Then 'If Minus is held
                    If chk2MotionForwardDownRetrigger.Checked = True Then soundbank.stopSound(SoundForwardAndDownWithMinus2)
                    soundbank.startSound(SoundForwardAndDownWithMinus2)
                    wiimoteForwardTriggerBuffer2 = BUFFERRESETVALUE2
                    Exit Sub

                ElseIf wiimote2state.ButtonState.Home Then 'If Home is held
                    If chk2MotionForwardDownRetrigger.Checked = True Then soundbank.stopSound(SoundForwardAndDownWithHome2)
                    soundbank.startSound(SoundForwardAndDownWithHome2)
                    wiimoteForwardTriggerBuffer2 = BUFFERRESETVALUE2
                    Exit Sub

                ElseIf wiimote2state.ButtonState.Plus Then 'If Plus is held
                    If chk2MotionForwardDownRetrigger.Checked = True Then soundbank.stopSound(SoundForwardAndDownWithPlus2)
                    soundbank.startSound(SoundForwardAndDownWithPlus2)
                    wiimoteForwardTriggerBuffer2 = BUFFERRESETVALUE2
                    Exit Sub

                Else
                    If chk2MotionForwardDownRetrigger.Checked = True Then soundbank.stopSound(SoundForwardAndDown2)
                    soundbank.startSound(SoundForwardAndDown2)
                    wiimoteForwardTriggerBuffer2 = BUFFERRESETVALUE2
                    Exit Sub

                End If

            End If

        End If

        'If the wiimote moves down
        If wiimoteDownTriggerBuffer2 < 0 Then

            y2 = CDbl(wiimote2state.AccelState.Values.Y)

            If chk2MotionDown.Checked = True And y2 < yMinThresh2 Then
                If chk2MotionDownRetrigger.Checked = True Then soundbank.stopSound(SoundDown2)
                soundbank.startSound(SoundDown2) ' trigger the kick drum samples
                wiimoteDownTriggerBuffer2 = BUFFERRESETVALUE2
                Exit Sub
            End If

        End If

        'Nunchuk
        If nunchukTriggerBuffer2 < 0 And chk2MotionNunchuk.Checked And wiimote2.WiimoteState.ExtensionType = ExtensionType.Nunchuk Then

            nunchuk2 = CDbl(wiimote2.WiimoteState.NunchukState.AccelState.Values.Y)

            'If The Nunchuk Moves Down And C Is Pressed
            If nunchuk2 > nunchukThresh2 And wiimote2.WiimoteState.NunchukState.C Then
                If chk2NunchukRetrigger.Checked Then
                    soundbank.stopSound(SoundNunchukWithC2)
                End If
                soundbank.startSound(SoundNunchukWithC2)
                nunchukTriggerBuffer2 = BUFFERRESETVALUE2
                Exit Sub

                'If The Nunchuk Moves Down And C Is Pressed
            ElseIf nunchuk2 > nunchukThresh2 And wiimote2.WiimoteState.NunchukState.Z Then
                If chk2NunchukRetrigger.Checked Then
                    soundbank.stopSound(SoundNunchukWithZ2)
                End If
                soundbank.startSound(SoundNunchukWithZ2)
                nunchukTriggerBuffer2 = BUFFERRESETVALUE2
                Exit Sub

                'If the nunchuk moves down and no buttons are pressed
            Else
                If nunchuk2 > nunchukThresh2 Then
                    If chk2NunchukRetrigger.Checked Then
                        soundbank.stopSound(SoundNunchuk2)
                    End If
                    soundbank.startSound(SoundNunchuk2)
                    nunchukTriggerBuffer2 = BUFFERRESETVALUE2
                    Exit Sub
                End If

            End If

        End If

    End Sub

    ' when the extension is plugged in or unplugged
    Private Sub wiimote1_WiimoteExtensionChanged(ByVal sender As Object, ByVal args As WiimoteLib.WiimoteExtensionChangedEventArgs) Handles wiimote1.WiimoteExtensionChanged
        If args.Inserted Then
            If args.ExtensionType = ExtensionType.Nunchuk Then
                wiimote1.SetReportType(InputReport.IRExtensionAccel, True)
            Else
                wiimote1.SetReportType(InputReport.ButtonsAccel, True)
            End If
        End If
    End Sub

    ' when the extension is plugged in or unplugged
    Private Sub wiimote2_WiimoteExtensionChanged(ByVal sender As Object, ByVal args As WiimoteLib.WiimoteExtensionChangedEventArgs) Handles wiimote2.WiimoteExtensionChanged
        If args.Inserted Then
            If args.ExtensionType = ExtensionType.Nunchuk Then
                wiimote2.SetReportType(InputReport.IRExtensionAccel, True)
            Else
                wiimote2.SetReportType(InputReport.ButtonsAccel, True)
            End If
        End If
    End Sub

#End Region

#Region "Preset Code"

    'Andre Knight
    ''' <summary>
    ''' Load preset file names into cmbPreset
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub LoadPresetsIntoCombobox()

        Try

            cmbPreset.Items.Clear()

            Dim presetfilename As String = vbNullString

            Dim directory As New DirectoryInfo(Application.StartupPath & "\Presets\")

            For Each file As FileInfo In directory.GetFiles()

                If file.Extension = ".preset" Then

                    presetfilename = file.Name.Substring(0, file.Name.Length - 7)

                    cmbPreset.Items.Add(presetfilename)

                End If

            Next file

        Catch ex As Exception

            Throw New Exception(ex.Message, ex)

        End Try

    End Sub

    ''' <summary>
    ''' Save the current settings as a preset
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub SavePreset()

        Try

            'New Code To Make Preset File More Intuitive
            Dim output As String = String.Empty

            output += "*************************" & vbCrLf
            output += "Wiimote 1 Thresholds" & vbCrLf
            output += "*************************" & vbCrLf
            output += "xMinThresh1: " & xMinThresh1 & vbCrLf
            output += "yMinThresh1: " & yMinThresh1 & vbCrLf
            output += "zMaxThresh1: " & zMaxThresh1 & vbCrLf
            output += "nunchukThresh1: " & nunchukThresh1 & vbCrLf

            output += "*************************" & vbCrLf
            output += "Wiimote 2 Thresholds" & vbCrLf
            output += "*************************" & vbCrLf
            output += "xMinThresh2: " & xMinThresh2 & vbCrLf
            output += "yMinThresh2: " & yMinThresh2 & vbCrLf
            output += "zMaxThresh2: " & zMaxThresh2 & vbCrLf
            output += "nunchukThresh2: " & nunchukThresh2 & vbCrLf

            output += "*************************" & vbCrLf
            output += "Wiimote 1 Enabled Motions" & vbCrLf
            output += "*************************" & vbCrLf
            output += "chk1MinXEnabled: " & chk1MotionDown.Checked & vbCrLf
            output += "chk1MinYEnabled: " & chk1MotionLeftRight.Checked & vbCrLf
            output += "chk1MaxZEnabled: " & chk1MotionForwardAndDown.Checked & vbCrLf
            output += "chk1NunChukEnabled: " & chk1MotionNunchuk.Checked & vbCrLf

            output += "*************************" & vbCrLf
            output += "Wiimote 2 Enabled Motions" & vbCrLf
            output += "*************************" & vbCrLf
            output += "chk2MinXEnabled: " & chk2MotionDown.Checked & vbCrLf
            output += "chk2MinYEnabled: " & chk2MotionLeftRight.Checked & vbCrLf
            output += "chk2MaxZEnabled: " & chk2MotionForwardDown.Checked & vbCrLf
            output += "chk2NunChukEnabled: " & chk2MotionNunchuk.Checked & vbCrLf

            output += "*************************" & vbCrLf
            output += "Wiimote 1 Retriggers" & vbCrLf
            output += "*************************" & vbCrLf
            output += "chk1MinXRetrigger: " & chk1MotionLeftRightRetrigger.Checked & vbCrLf
            output += "chk1MinYRetrigger: " & chk1MotionDownRetrigger.Checked & vbCrLf
            output += "chk1MaxZRetrigger: " & chk1MotionForwardDownRetrigger.Checked & vbCrLf
            output += "chk1NunchukRetrigger: " & chk1NunchukRetrigger.Checked & vbCrLf

            output += "*************************" & vbCrLf
            output += "Wiimote 2 Retriggers" & vbCrLf
            output += "*************************" & vbCrLf
            output += "chk2MinXRetrigger: " & chk2MotionLeftRightRetrigger.Checked & vbCrLf
            output += "chk2MinYRetrigger: " & chk2MotionDownRetrigger.Checked & vbCrLf
            output += "chk2MaxZRetrigger: " & chk2MotionForwardDownRetrigger.Checked & vbCrLf
            output += "chk2NunchukRetrigger: " & chk2NunchukRetrigger.Checked & vbCrLf

            output += "*************************" & vbCrLf
            output += "Wiimote 1 Motion Sounds" & vbCrLf
            output += "*************************" & vbCrLf
            output += "SoundLeftRight1: " & soundbank.getFilename(SoundLeftRight1) & vbCrLf
            output += "SoundLeftRightWithA1: " & soundbank.getFilename(SoundLeftRightWithA1) & vbCrLf
            output += "SoundForwardAndDown1: " & soundbank.getFilename(SoundForwardAndDown1) & vbCrLf
            output += "SoundForwardAndDownWithA1: " & soundbank.getFilename(SoundForwardAndDownWithA1) & vbCrLf
            output += "SoundForwardAndDownWithB1: " & soundbank.getFilename(SoundForwardAndDownWithB1) & vbCrLf
            output += "SoundForwardAndDownWithLeft1: " & soundbank.getFilename(SoundForwardAndDownWithLeft1) & vbCrLf
            output += "SoundForwardAndDownWithRight1: " & soundbank.getFilename(SoundForwardAndDownWithRight1) & vbCrLf
            output += "SoundForwardAndDownWithUp1: " & soundbank.getFilename(SoundForwardAndDownWithUp1) & vbCrLf
            output += "SoundForwardAndDownWithDown1: " & soundbank.getFilename(SoundForwardAndDownWithDown1) & vbCrLf
            output += "SoundForwardAndDownWithMinus1: " & soundbank.getFilename(SoundForwardAndDownWithMinus1) & vbCrLf
            output += "SoundForwardAndDownWithHome1: " & soundbank.getFilename(SoundForwardAndDownWithHome1) & vbCrLf
            output += "SoundForwardAndDownWithPlus1: " & soundbank.getFilename(SoundForwardAndDownWithPlus1) & vbCrLf
            output += "SoundDown1: " & soundbank.getFilename(SoundDown1) & vbCrLf
            output += "SoundNunchuk1: " & soundbank.getFilename(SoundNunchuk1) & vbCrLf
            output += "SoundNunchukWithC1: " & soundbank.getFilename(SoundNunchukWithC1) & vbCrLf
            output += "SoundNunchukWithZ1: " & soundbank.getFilename(SoundNunchukWithZ1) & vbCrLf


            output += "*************************" & vbCrLf
            output += "Wiimote 2 Motion Sounds" & vbCrLf
            output += "*************************" & vbCrLf
            output += "SoundLeftRight2: " & soundbank.getFilename(SoundLeftRight2) & vbCrLf
            output += "SoundLeftRightWithA2: " & soundbank.getFilename(SoundLeftRightWithA2) & vbCrLf
            output += "SoundForwardAndDown2: " & soundbank.getFilename(SoundForwardAndDown2) & vbCrLf
            output += "SoundForwardAndDownWithA2: " & soundbank.getFilename(SoundForwardAndDownWithA2) & vbCrLf
            output += "SoundForwardAndDownWithB2: " & soundbank.getFilename(SoundForwardAndDownWithB2) & vbCrLf
            output += "SoundForwardAndDownWithLeft2: " & soundbank.getFilename(SoundForwardAndDownWithLeft2) & vbCrLf
            output += "SoundForwardAndDownWithRight2: " & soundbank.getFilename(SoundForwardAndDownWithRight2) & vbCrLf
            output += "SoundForwardAndDownWithUp2: " & soundbank.getFilename(SoundForwardAndDownWithUp2) & vbCrLf
            output += "SoundForwardAndDownWithDown2: " & soundbank.getFilename(SoundForwardAndDownWithDown2) & vbCrLf
            output += "SoundForwardAndDownWithMinus2: " & soundbank.getFilename(SoundForwardAndDownWithMinus2) & vbCrLf
            output += "SoundForwardAndDownWithHome2: " & soundbank.getFilename(SoundForwardAndDownWithHome2) & vbCrLf
            output += "SoundForwardAndDownWithPlus2: " & soundbank.getFilename(SoundForwardAndDownWithPlus2) & vbCrLf
            output += "SoundDown2: " & soundbank.getFilename(SoundDown2) & vbCrLf
            output += "SoundNunchuk2: " & soundbank.getFilename(SoundNunchuk2) & vbCrLf
            output += "SoundNunchukWithC2: " & soundbank.getFilename(SoundNunchukWithC2) & vbCrLf
            output += "SoundNunchukWithZ2: " & soundbank.getFilename(SoundNunchukWithZ2) & vbCrLf

            If cmbPreset.Text.Length > 0 Then

                SaveTextToFile(output, Application.StartupPath & "\Presets\" & cmbPreset.Text & ".preset")

            Else

                CreateNewPresetFileToolStripMenuItem_Click(New Object, New EventArgs)

            End If

        Catch ex As Exception

            Throw New Exception(ex.Message, ex)

        End Try

    End Sub

    ''' <summary>
    ''' Save the current settings as a preset
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub SavePreset(ByVal pPresetName As String)

        Try

            Dim output As String = String.Empty

            output += "*************************" & vbCrLf
            output += "Wiimote 1 Thresholds" & vbCrLf
            output += "*************************" & vbCrLf
            output += "xMinThresh1: " & xMinThresh1 & vbCrLf
            output += "yMinThresh1: " & yMinThresh1 & vbCrLf
            output += "zMaxThresh1: " & zMaxThresh1 & vbCrLf
            output += "nunchukThresh1: " & nunchukThresh1 & vbCrLf

            output += "*************************" & vbCrLf
            output += "Wiimote 2 Thresholds" & vbCrLf
            output += "*************************" & vbCrLf
            output += "xMinThresh2: " & xMinThresh2 & vbCrLf
            output += "yMinThresh2: " & yMinThresh2 & vbCrLf
            output += "zMaxThresh2: " & zMaxThresh2 & vbCrLf
            output += "nunchukThresh2: " & nunchukThresh2 & vbCrLf

            output += "*************************" & vbCrLf
            output += "Wiimote 1 Enabled Motions" & vbCrLf
            output += "*************************" & vbCrLf
            output += "chk1MinXEnabled: " & chk1MotionDown.Checked & vbCrLf
            output += "chk1MinYEnabled: " & chk1MotionLeftRight.Checked & vbCrLf
            output += "chk1MaxZEnabled: " & chk1MotionForwardAndDown.Checked & vbCrLf
            output += "chk1NunChukEnabled: " & chk1MotionNunchuk.Checked & vbCrLf

            output += "*************************" & vbCrLf
            output += "Wiimote 2 Enabled Motions" & vbCrLf
            output += "*************************" & vbCrLf
            output += "chk2MinXEnabled: " & chk2MotionDown.Checked & vbCrLf
            output += "chk2MinYEnabled: " & chk2MotionLeftRight.Checked & vbCrLf
            output += "chk2MaxZEnabled: " & chk2MotionForwardDown.Checked & vbCrLf
            output += "chk2NunChukEnabled: " & chk2MotionNunchuk.Checked & vbCrLf

            output += "*************************" & vbCrLf
            output += "Wiimote 1 Retriggers" & vbCrLf
            output += "*************************" & vbCrLf
            output += "chk1MinXRetrigger: " & chk1MotionLeftRightRetrigger.Checked & vbCrLf
            output += "chk1MinYRetrigger: " & chk1MotionDownRetrigger.Checked & vbCrLf
            output += "chk1MaxZRetrigger: " & chk1MotionForwardDownRetrigger.Checked & vbCrLf
            output += "chk1NunchukRetrigger: " & chk1NunchukRetrigger.Checked & vbCrLf

            output += "*************************" & vbCrLf
            output += "Wiimote 2 Retriggers" & vbCrLf
            output += "*************************" & vbCrLf
            output += "chk2MinXRetrigger: " & chk2MotionLeftRightRetrigger.Checked & vbCrLf
            output += "chk2MinYRetrigger: " & chk2MotionDownRetrigger.Checked & vbCrLf
            output += "chk2MaxZRetrigger: " & chk2MotionForwardDownRetrigger.Checked & vbCrLf
            output += "chk2NunchukRetrigger: " & chk2NunchukRetrigger.Checked & vbCrLf

            output += "*************************" & vbCrLf
            output += "Wiimote 1 Motion Sounds" & vbCrLf
            output += "*************************" & vbCrLf
            output += "SoundLeftRight1: " & soundbank.getFilename(SoundLeftRight1) & vbCrLf
            output += "SoundLeftRightWithA1: " & soundbank.getFilename(SoundLeftRightWithA1) & vbCrLf
            output += "SoundForwardAndDown1: " & soundbank.getFilename(SoundForwardAndDown1) & vbCrLf
            output += "SoundForwardAndDownWithA1: " & soundbank.getFilename(SoundForwardAndDownWithA1) & vbCrLf
            output += "SoundForwardAndDownWithB1: " & soundbank.getFilename(SoundForwardAndDownWithB1) & vbCrLf
            output += "SoundForwardAndDownWithLeft1: " & soundbank.getFilename(SoundForwardAndDownWithLeft1) & vbCrLf
            output += "SoundForwardAndDownWithRight1: " & soundbank.getFilename(SoundForwardAndDownWithRight1) & vbCrLf
            output += "SoundForwardAndDownWithUp1: " & soundbank.getFilename(SoundForwardAndDownWithUp1) & vbCrLf
            output += "SoundForwardAndDownWithDown1: " & soundbank.getFilename(SoundForwardAndDownWithDown1) & vbCrLf
            output += "SoundForwardAndDownWithMinus1: " & soundbank.getFilename(SoundForwardAndDownWithMinus1) & vbCrLf
            output += "SoundForwardAndDownWithHome1: " & soundbank.getFilename(SoundForwardAndDownWithHome1) & vbCrLf
            output += "SoundForwardAndDownWithPlus1: " & soundbank.getFilename(SoundForwardAndDownWithPlus1) & vbCrLf
            output += "SoundDown1: " & soundbank.getFilename(SoundDown1) & vbCrLf
            output += "SoundNunchuk1: " & soundbank.getFilename(SoundNunchuk1) & vbCrLf
            output += "SoundNunchukWithC1: " & soundbank.getFilename(SoundNunchukWithC1) & vbCrLf
            output += "SoundNunchukWithZ1: " & soundbank.getFilename(SoundNunchukWithZ1) & vbCrLf


            output += "*************************" & vbCrLf
            output += "Wiimote 2 Motion Sounds" & vbCrLf
            output += "*************************" & vbCrLf
            output += "SoundLeftRight2: " & soundbank.getFilename(SoundLeftRight2) & vbCrLf
            output += "SoundLeftRightWithA2: " & soundbank.getFilename(SoundLeftRightWithA2) & vbCrLf
            output += "SoundForwardAndDown2: " & soundbank.getFilename(SoundForwardAndDown2) & vbCrLf
            output += "SoundForwardAndDownWithA2: " & soundbank.getFilename(SoundForwardAndDownWithA2) & vbCrLf
            output += "SoundForwardAndDownWithB2: " & soundbank.getFilename(SoundForwardAndDownWithB2) & vbCrLf
            output += "SoundForwardAndDownWithLeft2: " & soundbank.getFilename(SoundForwardAndDownWithLeft2) & vbCrLf
            output += "SoundForwardAndDownWithRight2: " & soundbank.getFilename(SoundForwardAndDownWithRight2) & vbCrLf
            output += "SoundForwardAndDownWithUp2: " & soundbank.getFilename(SoundForwardAndDownWithUp2) & vbCrLf
            output += "SoundForwardAndDownWithDown2: " & soundbank.getFilename(SoundForwardAndDownWithDown2) & vbCrLf
            output += "SoundForwardAndDownWithMinus2: " & soundbank.getFilename(SoundForwardAndDownWithMinus2) & vbCrLf
            output += "SoundForwardAndDownWithHome2: " & soundbank.getFilename(SoundForwardAndDownWithHome2) & vbCrLf
            output += "SoundForwardAndDownWithPlus2: " & soundbank.getFilename(SoundForwardAndDownWithPlus2) & vbCrLf
            output += "SoundDown2: " & soundbank.getFilename(SoundDown2) & vbCrLf
            output += "SoundNunchuk2: " & soundbank.getFilename(SoundNunchuk2) & vbCrLf
            output += "SoundNunchukWithC2: " & soundbank.getFilename(SoundNunchukWithC2) & vbCrLf
            output += "SoundNunchukWithZ2: " & soundbank.getFilename(SoundNunchukWithZ2) & vbCrLf

            'Create and save the .preset file
            SaveTextToFile(output, Application.StartupPath & "\Presets\" & pPresetName & ".preset")

        Catch ex As Exception

            Throw New Exception(ex.Message, ex)

        End Try

    End Sub

    ''' <summary>
    ''' Load Preset File Settings
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub LoadPreset()

        Try

            If cmbPreset.Text.Length = 0 Then Exit Sub

            Dim streamreader As New StreamReader(Application.StartupPath & "\Presets\" & cmbPreset.Text & ".preset")

            Dim readstring As String = streamreader.ReadLine()

            Dim propertysetting As String = String.Empty

            If readstring.Contains(":") Then

                propertysetting = readstring.Substring(0, readstring.IndexOf(":"))

            Else

                propertysetting = String.Empty

            End If

            Dim soundfilename As String = String.Empty

            While readstring <> String.Empty

                Select Case propertysetting

                    'Wiimote 1 Threshholds
                    Case "xMinThresh1"
                        xMinThresh1 = readstring.Substring(readstring.IndexOf(":") + 2)
                        tb1MinX.Value = xMinThresh1 * 10
                        lbl1MinXThresh.Text = xMinThresh1

                    Case "yMinThresh1"
                        yMinThresh1 = readstring.Substring(readstring.IndexOf(":") + 2)
                        tb1MinY.Value = yMinThresh1 * 10
                        lbl1MinYThresh.Text = yMinThresh1

                    Case "zMaxThresh1"
                        zMaxThresh1 = CDbl(readstring.Substring(readstring.IndexOf(":") + 2))
                        tb1MaxZ.Value = zMaxThresh1 * 10
                        lbl1MaxZThresh.Text = zMaxThresh1

                    Case "nunchukThresh1"
                        nunchukThresh1 = CDbl(readstring.Substring(readstring.IndexOf(":") + 2))
                        tb1Nunchuk.Value = nunchukThresh1 * 10
                        lbl1NunchukThresh.Text = nunchukThresh1

                        'Wiimote 2 Threshholds
                    Case "xMinThresh2"
                        xMinThresh2 = readstring.Substring(readstring.IndexOf(":") + 2)
                        tb2MinX.Value = xMinThresh2 * 10
                        lbl2MinXThresh.Text = xMinThresh2

                    Case "yMinThresh2"
                        yMinThresh2 = readstring.Substring(readstring.IndexOf(":") + 2)
                        tb2MinY.Value = yMinThresh2 * 10
                        lbl2MinYThresh.Text = yMinThresh2

                    Case "zMaxThresh2"
                        zMaxThresh2 = CDbl(readstring.Substring(readstring.IndexOf(":") + 2))
                        tb2MaxZ.Value = zMaxThresh2 * 10
                        lbl2MaxZThresh.Text = zMaxThresh2

                    Case "nunchukThresh2"
                        nunchukThresh2 = CDbl(readstring.Substring(readstring.IndexOf(":") + 2))
                        tb2Nunchuk.Value = nunchukThresh2 * 10
                        lbl2NunchukThresh.Text = nunchukThresh2

                        'Wiimote 1 Enabled Motions
                    Case "chk1MinXEnabled"
                        chk1MotionDown.Checked = CBool(readstring.Substring(readstring.IndexOf(":") + 2))

                    Case "chk1MinYEnabled"
                        chk1MotionLeftRight.Checked = CBool(readstring.Substring(readstring.IndexOf(":") + 2))

                    Case "chk1MaxZEnabled"
                        chk1MotionForwardAndDown.Checked = CBool(readstring.Substring(readstring.IndexOf(":") + 2))

                    Case "chk1NunChukEnabled"
                        chk1MotionNunchuk.Checked = CBool(readstring.Substring(readstring.IndexOf(":") + 2))

                        'Wiimote 2 Enabled Motions
                    Case "chk2MinXEnabled"
                        chk2MotionDown.Checked = CBool(readstring.Substring(readstring.IndexOf(":") + 2))

                    Case "chk2MinYEnabled"
                        chk2MotionLeftRight.Checked = CBool(readstring.Substring(readstring.IndexOf(":") + 2))

                    Case "chk2MaxZEnabled"
                        chk2MotionForwardDown.Checked = CBool(readstring.Substring(readstring.IndexOf(":") + 2))

                    Case "chk2NunChukEnabled"
                        chk2MotionNunchuk.Checked = CBool(readstring.Substring(readstring.IndexOf(":") + 2))

                        'Wiimote 1 Retriggers
                    Case "chk1MinXRetrigger"
                        chk1MotionLeftRightRetrigger.Checked = CBool(readstring.Substring(readstring.IndexOf(":") + 2))

                    Case "chk1MinYRetrigger"
                        chk1MotionDownRetrigger.Checked = CBool(readstring.Substring(readstring.IndexOf(":") + 2))

                    Case "chk1MaxZRetrigger"
                        chk1MotionForwardDownRetrigger.Checked = CBool(readstring.Substring(readstring.IndexOf(":") + 2))

                    Case "chk1NunchukRetrigger"
                        chk1NunchukRetrigger.Checked = CBool(readstring.Substring(readstring.IndexOf(":") + 2))

                        'Wiimote 2 Retriggers
                    Case "chk2MinXRetrigger"
                        chk2MotionLeftRightRetrigger.Checked = CBool(readstring.Substring(readstring.IndexOf(":") + 2))

                    Case "chk2MinYRetrigger"
                        chk2MotionDownRetrigger.Checked = CBool(readstring.Substring(readstring.IndexOf(":") + 2))

                    Case "chk2MaxZRetrigger"
                        chk2MotionForwardDownRetrigger.Checked = CBool(readstring.Substring(readstring.IndexOf(":") + 2))

                    Case "chk2NunchukRetrigger"
                        chk2NunchukRetrigger.Checked = CBool(readstring.Substring(readstring.IndexOf(":") + 2))

                        'Wiimote 1 Motion Sounds
                    Case "SoundLeftRight1"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundLeftRight1 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundLeftRight1")
                        If soundfilename = String.Empty Then
                            lblSoundLeftRight1.Text = "Left Right Not Set"
                        End If

                    Case "SoundLeftRightWithA1"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundLeftRightWithA1 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundLeftRightWithA1")
                        If soundfilename = String.Empty Then
                            lblSoundLeftRightWithA1.Text = "Left Right With A Not Set"
                        End If

                    Case "SoundForwardAndDown1"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundForwardAndDown1 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundForwardAndDown1")
                        If soundfilename = String.Empty Then
                            lblSoundForwardAndDown1.Text = "Forward And Down  Not Set"
                        End If

                    Case "SoundForwardAndDownWithA1"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundForwardAndDownWithA1 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundForwardAndDownWithA1")
                        If soundfilename = String.Empty Then
                            lblSoundForwardAndDownWithA1.Text = "Forward And Down With A Not Set"
                        End If

                    Case "SoundForwardAndDownWithB1"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundForwardAndDownWithB1 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundForwardAndDownWithB1")
                        If soundfilename = String.Empty Then
                            lblSoundForwardAndDownWithB1.Text = "Forward And Down With B Not Set"
                        End If

                    Case "SoundDown1"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundDown1 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundDown1")
                        If soundfilename = String.Empty Then
                            lblSoundDown1.Text = "Down Not Set"
                        End If

                    Case "SoundNunchuk1"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundNunchuk1 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundNunchuk1")
                        If soundfilename = String.Empty Then
                            lblSoundNunchuk1.Text = "Nunchuk Not Set"
                        End If

                    Case "SoundNunchukWithC1"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundNunchukWithC1 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundNunchukWithC1")
                        If soundfilename = String.Empty Then
                            lblSoundNunchukWithC1.Text = "Nunchuk With C Not Set"
                        End If

                    Case "SoundNunchukWithZ1"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundNunchukWithZ1 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundNunchukWithZ1")
                        If soundfilename = String.Empty Then
                            lblSoundNunchukWithZ1.Text = "Nunchuk With Z Not Set"
                        End If

                    Case "SoundForwardAndDownWithLeft1"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundForwardAndDownWithLeft1 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundForwardAndDownWithLeft1")
                        If soundfilename = String.Empty Then
                            lblSoundForwardAndDownWithLeft1.Text = "Forward Down With Left Not Set"
                        End If

                    Case "SoundForwardAndDownWithUp1"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundForwardAndDownWithUp1 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundForwardAndDownWithUp1")
                        If soundfilename = String.Empty Then
                            lblSoundForwardAndDownWithUp1.Text = "Forward Down With Up Not Set"
                        End If

                    Case "SoundForwardAndDownWithRight1"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundForwardAndDownWithRight1 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundForwardAndDownWithRight1")
                        If soundfilename = String.Empty Then
                            lblSoundForwardAndDownWithRight1.Text = "Forward Down With Right Not Set"
                        End If

                    Case "SoundForwardAndDownWithDown1"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundForwardAndDownWithDown1 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundForwardAndDownWithDown1")
                        If soundfilename = String.Empty Then
                            lblSoundForwardAndDownWithDown1.Text = "Forward Down With Down Not Set"
                        End If

                    Case "SoundForwardAndDownWithMinus1"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundForwardAndDownWithMinus1 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundForwardAndDownWithMinus1")
                        If soundfilename = String.Empty Then
                            lblSoundForwardAndDownWithMinus1.Text = "Forward Down With Minus Not Set"
                        End If

                    Case "SoundForwardAndDownWithHome1"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundForwardAndDownWithHome1 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundForwardAndDownWithHome1")
                        If soundfilename = String.Empty Then
                            lblSoundForwardAndDownWithHome1.Text = "Forward Down With Home Not Set"
                        End If

                    Case "SoundForwardAndDownWithPlus1"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundForwardAndDownWithPlus1 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundForwardAndDownWithPlus1")
                        If soundfilename = String.Empty Then
                            lblSoundForwardAndDownWithPlus1.Text = "Forward Down With Plus Not Set"
                        End If

                        'Wiimote 2 Motion Sounds
                    Case "SoundLeftRight2"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundLeftRight2 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundLeftRight2")
                        If soundfilename = String.Empty Then
                            lblSoundLeftRight2.Text = "Left Right Not Set"
                        End If

                    Case "SoundLeftRightWithA2"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundLeftRightWithA2 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundLeftRightWithA2")
                        If soundfilename = String.Empty Then
                            lblSoundLeftRightWithA2.Text = "Left Right With A Not Set"
                        End If

                    Case "SoundForwardAndDown2"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundForwardAndDown2 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundForwardAndDown2")
                        If soundfilename = String.Empty Then
                            lblSoundForwardAndDown2.Text = "Forward And Down  Not Set"
                        End If

                    Case "SoundForwardAndDownWithA2"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundForwardAndDownWithA2 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundForwardAndDownWithA2")
                        If soundfilename = String.Empty Then
                            lblSoundForwardAndDownWithA2.Text = "Forward And Down With A Not Set"
                        End If

                    Case "SoundForwardAndDownWithB2"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundForwardAndDownWithB2 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundForwardAndDownWithB2")
                        If soundfilename = String.Empty Then
                            lblSoundForwardAndDownWithB2.Text = "Forward And Down With B Not Set"
                        End If

                    Case "SoundDown2"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundDown2 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundDown2")
                        If soundfilename = String.Empty Then
                            lblSoundDown2.Text = "Down Not Set"
                        End If

                    Case "SoundNunchuk2"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundNunchuk2 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundNunchuk2")
                        If soundfilename = String.Empty Then
                            lblSoundNunchuk2.Text = "Nunchuk Not Set"
                        End If

                    Case "SoundNunchukWithC2"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundNunchukWithC2 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundNunchukWithC2")
                        If soundfilename = String.Empty Then
                            lblSoundNunchukWithC2.Text = "Nunchuk With C Not Set"
                        End If

                    Case "SoundNunchukWithZ2"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundNunchukWithZ2 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundNunchukWithZ2")
                        If soundfilename = String.Empty Then
                            lblSoundNunchukWithZ2.Text = "Nunchuk With Z Not Set"
                        End If

                    Case "SoundForwardAndDownWithLeft2"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundForwardAndDownWithLeft2 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundForwardAndDownWithLeft2")
                        If soundfilename = String.Empty Then
                            lblSoundForwardAndDownWithLeft2.Text = "Forward Down With Left Not Set"
                        End If

                    Case "SoundForwardAndDownWithUp2"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundForwardAndDownWithUp2 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundForwardAndDownWithUp2")
                        If soundfilename = String.Empty Then
                            lblSoundForwardAndDownWithUp2.Text = "Forward Down With Up Not Set"
                        End If

                    Case "SoundForwardAndDownWithRight2"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundForwardAndDownWithRight2 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundForwardAndDownWithRight2")
                        If soundfilename = String.Empty Then
                            lblSoundForwardAndDownWithRight2.Text = "Forward Down With Right Not Set"
                        End If

                    Case "SoundForwardAndDownWithDown2"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundForwardAndDownWithDown2 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundForwardAndDownWithDown2")
                        If soundfilename = String.Empty Then
                            lblSoundForwardAndDownWithDown2.Text = "Forward Down With Down Not Set"
                        End If

                    Case "SoundForwardAndDownWithMinus2"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundForwardAndDownWithMinus2 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundForwardAndDownWithMinus2")
                        If soundfilename = String.Empty Then
                            lblSoundForwardAndDownWithMinus2.Text = "Forward Down With Minus Not Set"
                        End If

                    Case "SoundForwardAndDownWithHome2"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundForwardAndDownWithHome2 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundForwardAndDownWithHome2")
                        If soundfilename = String.Empty Then
                            lblSoundForwardAndDownWithHome2.Text = "Forward Down With Home Not Set"
                        End If

                    Case "SoundForwardAndDownWithPlus2"
                        soundfilename = readstring.Substring(readstring.IndexOf(":") + 2)
                        SoundForwardAndDownWithPlus2 = soundbank.addSound(soundfilename)
                        SetLabelWithPresetFileName(soundfilename, "SoundForwardAndDownWithPlus2")
                        If soundfilename = String.Empty Then
                            lblSoundForwardAndDownWithPlus2.Text = "Forward Down With Plus Not Set"
                        End If

                End Select

                readstring = streamreader.ReadLine()

                If readstring <> String.Empty Then

                    If readstring.Contains(":") Then

                        propertysetting = readstring.Substring(0, readstring.IndexOf(":"))

                    Else

                        propertysetting = String.Empty

                    End If

                End If

            End While

            streamreader.Close()

        Catch ex As Exception

            MessageBox.Show(ex.Message, "Loading Preset File Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

        End Try

    End Sub

    ''' <summary>
    ''' Set Labels With File Name Loaded From Preset File
    ''' </summary>
    ''' <param name="pPresetFileName"></param>
    ''' <param name="pMapping"></param>
    ''' <remarks></remarks>
    Private Sub SetLabelWithPresetFileName(ByVal pPresetFileName As String, ByVal pMapping As String)

        Dim PresetFile As FileInfo

        Try

            If pPresetFileName <> String.Empty Then

                PresetFile = My.Computer.FileSystem.GetFileInfo(pPresetFileName)

                Select Case pMapping

                    'Wiimote 1
                    Case "SoundLeftRight1"
                        lblSoundLeftRight1.Text = PresetFile.Name

                    Case "SoundLeftRightWithA1"
                        lblSoundLeftRightWithA1.Text = PresetFile.Name

                    Case "SoundDown1"
                        lblSoundDown1.Text = PresetFile.Name

                    Case "SoundNunchuk1"
                        lblSoundNunchuk1.Text = PresetFile.Name

                    Case "SoundNunchukWithC1"
                        lblSoundNunchukWithC1.Text = PresetFile.Name

                    Case "SoundNunchukWithZ1"
                        lblSoundNunchukWithZ1.Text = PresetFile.Name

                    Case "SoundForwardAndDown1"
                        lblSoundForwardAndDown1.Text = PresetFile.Name

                    Case "SoundForwardAndDownWithA1"
                        lblSoundForwardAndDownWithA1.Text = PresetFile.Name

                    Case "SoundForwardAndDownWithB1"
                        lblSoundForwardAndDownWithB1.Text = PresetFile.Name

                    Case "SoundForwardAndDownWithUp1"
                        lblSoundForwardAndDownWithUp1.Text = PresetFile.Name

                    Case "SoundForwardAndDownWithDown1"
                        lblSoundForwardAndDownWithDown1.Text = PresetFile.Name

                    Case "SoundForwardAndDownWithLeft1"
                        lblSoundForwardAndDownWithLeft1.Text = PresetFile.Name

                    Case "SoundForwardAndDownWithRight1"
                        lblSoundForwardAndDownWithRight1.Text = PresetFile.Name

                    Case "SoundForwardAndDownWithMinus1"
                        lblSoundForwardAndDownWithMinus1.Text = PresetFile.Name

                    Case "SoundForwardAndDownWithHome1"
                        lblSoundForwardAndDownWithHome1.Text = PresetFile.Name

                    Case "SoundForwardAndDownWithPlus1"
                        lblSoundForwardAndDownWithPlus1.Text = PresetFile.Name

                        'Wiimote 2
                    Case "SoundLeftRight2"
                        lblSoundLeftRight2.Text = PresetFile.Name

                    Case "SoundLeftRightWithA2"
                        lblSoundLeftRightWithA2.Text = PresetFile.Name

                    Case "SoundDown2"
                        lblSoundDown2.Text = PresetFile.Name

                    Case "SoundNunchuk2"
                        lblSoundNunchuk2.Text = PresetFile.Name

                    Case "SoundNunchukWithC2"
                        lblSoundNunchukWithC2.Text = PresetFile.Name

                    Case "SoundNunchukWithZ2"
                        lblSoundNunchukWithZ2.Text = PresetFile.Name

                    Case "SoundForwardAndDown2"
                        lblSoundForwardAndDown2.Text = PresetFile.Name

                    Case "SoundForwardAndDownWithA2"
                        lblSoundForwardAndDownWithA2.Text = PresetFile.Name

                    Case "SoundForwardAndDownWithB2"
                        lblSoundForwardAndDownWithB2.Text = PresetFile.Name

                    Case "SoundForwardAndDownWithUp2"
                        lblSoundForwardAndDownWithUp2.Text = PresetFile.Name

                    Case "SoundForwardAndDownWithDown2"
                        lblSoundForwardAndDownWithDown2.Text = PresetFile.Name

                    Case "SoundForwardAndDownWithLeft2"
                        lblSoundForwardAndDownWithLeft2.Text = PresetFile.Name

                    Case "SoundForwardAndDownWithRight2"
                        lblSoundForwardAndDownWithRight2.Text = PresetFile.Name

                    Case "SoundForwardAndDownWithMinus2"
                        lblSoundForwardAndDownWithMinus2.Text = PresetFile.Name

                    Case "SoundForwardAndDownWithHome2"
                        lblSoundForwardAndDownWithHome2.Text = PresetFile.Name

                    Case "SoundForwardAndDownWithPlus2"
                        lblSoundForwardAndDownWithPlus2.Text = PresetFile.Name

                End Select

            End If

        Catch ex As Exception

            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try


    End Sub

    Private Sub CreateProgramPresetFiles()

        CreateStandardDrumKitPresetFile()

        'CreateBassGuitarPresetFile()

        'CreateWeirdnessPresetFile()

    End Sub

    Private Sub CreateStandardDrumKitPresetFile()

        If File.Exists(Application.StartupPath & "\Presets\Standard Drum Kit.preset") Then

            Exit Sub

        End If

        Dim output As String = String.Empty

        output += "*************************" & vbCrLf
        output += "Wiimote 1 Thresholds" & vbCrLf
        output += "*************************" & vbCrLf
        output += "xMinThresh1: -3" & vbCrLf
        output += "yMinThresh1: -3" & vbCrLf
        output += "zMaxThresh1: 4" & vbCrLf
        output += "nunchukThresh1: 2" & vbCrLf

        output += "*************************" & vbCrLf
        output += "Wiimote 2 Thresholds" & vbCrLf
        output += "*************************" & vbCrLf
        output += "xMinThresh2: 3" & vbCrLf
        output += "yMinThresh2: -3" & vbCrLf
        output += "zMaxThresh2: 4" & vbCrLf
        output += "nunchukThresh2: 2" & vbCrLf

        output += "*************************" & vbCrLf
        output += "Wiimote 1 Enabled Motions" & vbCrLf
        output += "*************************" & vbCrLf
        output += "chk1MinXEnabled: True" & vbCrLf
        output += "chk1MinYEnabled: True" & vbCrLf
        output += "chk1MaxZEnabled: True" & vbCrLf
        output += "chk1NunChukEnabled: True" & vbCrLf

        output += "*************************" & vbCrLf
        output += "Wiimote 2 Enabled Motions" & vbCrLf
        output += "*************************" & vbCrLf
        output += "chk2MinXEnabled: True" & vbCrLf
        output += "chk2MinYEnabled: True" & vbCrLf
        output += "chk2MaxZEnabled: True" & vbCrLf
        output += "chk2NunChukEnabled: True" & vbCrLf

        output += "*************************" & vbCrLf
        output += "Wiimote 1 Retriggers" & vbCrLf
        output += "*************************" & vbCrLf
        output += "chk1MinXRetrigger: True" & vbCrLf
        output += "chk1MinYRetrigger: True" & vbCrLf
        output += "chk1MaxZRetrigger: True" & vbCrLf
        output += "chk1NunchukRetrigger: True" & vbCrLf

        output += "*************************" & vbCrLf
        output += "Wiimote 2 Retriggers" & vbCrLf
        output += "*************************" & vbCrLf
        output += "chk2MinXRetrigger: True" & vbCrLf
        output += "chk2MinYRetrigger: True" & vbCrLf
        output += "chk2MaxZRetrigger: True" & vbCrLf
        output += "chk2NunchukRetrigger: False" & vbCrLf

        output += "*************************" & vbCrLf
        output += "Wiimote 1 Motion Sounds" & vbCrLf
        output += "*************************" & vbCrLf
        output += "SoundLeftRight1: " & Application.StartupPath & "\Drum Samples\Snares\Snare Low.wav" & vbCrLf
        output += "SoundLeftRightWithA1: " & Application.StartupPath & "\Drum Samples\Snares\Snare Low.wav" & vbCrLf
        output += "SoundForwardAndDown1: " & Application.StartupPath & "\Drum Samples\Cymbals\Ride.wav" & vbCrLf
        output += "SoundForwardAndDownWithA1: " & Application.StartupPath & "\Drum Samples\Standard Drum Kit\Open High Hat.wav" & vbCrLf
        output += "SoundForwardAndDownWithB1: " & Application.StartupPath & "\Drum Samples\Standard Drum Kit\Closed High Hat.wav" & vbCrLf
        output += "SoundForwardAndDownWithLeft1: " & Application.StartupPath & "\Drum Samples\Cymbals\Cymbal Splash.WAV" & vbCrLf
        output += "SoundForwardAndDownWithRight1: " & Application.StartupPath & "\Drum Samples\Cymbals\Crash.wav" & vbCrLf
        output += "SoundForwardAndDownWithUp1: " & Application.StartupPath & "\Drum Samples\Standard Drum Kit\Crash.wav" & vbCrLf
        output += "SoundForwardAndDownWithDown1: " & Application.StartupPath & "\Drum Samples\Cymbals\Crash 2.wav" & vbCrLf
        output += "SoundForwardAndDownWithMinus1: " & Application.StartupPath & "\Drum Samples\Standard Drum Kit\TomHigh.wav" & vbCrLf
        output += "SoundForwardAndDownWithHome1: " & Application.StartupPath & "\Drum Samples\Standard Drum Kit\TomMid.wav" & vbCrLf
        output += "SoundForwardAndDownWithPlus1: " & Application.StartupPath & "\Drum Samples\Standard Drum Kit\TomLow.wav" & vbCrLf
        output += "SoundDown1: " & Application.StartupPath & "\Drum Samples\Cymbals\China Cymbal Gong Low.wav" & vbCrLf
        output += "SoundNunchuk1: " & Application.StartupPath & "\Drum Samples\Kick Drums\bright_kick_011.wav" & vbCrLf
        output += "SoundNunchukWithC1: " & Application.StartupPath & "\Drum Samples\Kick Drums\bright_kick_012.wav" & vbCrLf
        output += "SoundNunchukWithZ1: " & Application.StartupPath & "\Drum Samples\Kick Drums\tight_kick_017.wav" & vbCrLf

        output += "*************************" & vbCrLf
        output += "Wiimote 2 Motion Sounds" & vbCrLf
        output += "*************************" & vbCrLf
        output += "SoundLeftRight2: " & Application.StartupPath & "\Drum Samples\Snares\Snare Low.wav" & vbCrLf
        output += "SoundLeftRightWithA2: " & Application.StartupPath & "\Drum Samples\Snares\Snare Low.wav" & vbCrLf
        output += "SoundForwardAndDown2: " & Application.StartupPath & "\Drum Samples\Cymbals\Ride.wav" & vbCrLf
        output += "SoundForwardAndDownWithA2: " & Application.StartupPath & "\Drum Samples\Standard Drum Kit\Open High Hat.wav" & vbCrLf
        output += "SoundForwardAndDownWithB2: " & Application.StartupPath & "\Drum Samples\Standard Drum Kit\Closed High Hat.wav" & vbCrLf
        output += "SoundForwardAndDownWithLeft2: " & Application.StartupPath & "\Drum Samples\Cymbals\Cymbal Splash.WAV" & vbCrLf
        output += "SoundForwardAndDownWithRight2: " & Application.StartupPath & "\Drum Samples\Standard Drum Kit\Crash.wav" & vbCrLf
        output += "SoundForwardAndDownWithUp2: " & Application.StartupPath & "\Drum Samples\Standard Drum Kit\Crash.wav" & vbCrLf
        output += "SoundForwardAndDownWithDown2: " & Application.StartupPath & "\Drum Samples\Cymbals\Crash 2.wav" & vbCrLf
        output += "SoundForwardAndDownWithMinus2: " & Application.StartupPath & "\Drum Samples\Standard Drum Kit\TomHigh.wav" & vbCrLf
        output += "SoundForwardAndDownWithHome2: " & Application.StartupPath & "\Drum Samples\Standard Drum Kit\TomMid.wav" & vbCrLf
        output += "SoundForwardAndDownWithPlus2: " & Application.StartupPath & "\Drum Samples\Standard Drum Kit\TomLow.wav" & vbCrLf
        output += "SoundDown2: " & Application.StartupPath & "\Drum Samples\Cymbals\China Cymbal Gong.wav" & vbCrLf
        output += "SoundNunchuk2: " & Application.StartupPath & "\Drum Samples\Kick Drums\bright_kick_011.wav" & vbCrLf
        output += "SoundNunchukWithC2: " & Application.StartupPath & "\Drum Samples\Kick Drums\bright_kick_012.wav" & vbCrLf
        output += "SoundNunchukWithZ2: " & Application.StartupPath & "\Drum Samples\Kick Drums\tight_kick_017.wav" & vbCrLf

        My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\Presets\Standard Drum Kit.preset", output, False)

    End Sub

    Private Sub CreateBassGuitarPresetFile()

        If File.Exists(Application.StartupPath & "\Presets\Bass Guitar.preset") Then

            Exit Sub

        End If

        Dim output As String = vbNullString

        'Save the thresholds
        output += "-3.9^-2.8^4.2^1.4^"

        'Save the enabled
        output += "True^True^True^True^"

        'Save the retriggers
        output += "True^True^True^True^"

        output += Application.StartupPath & "\Drum Samples\Bass Notes\A1 Short.wav^"
        output += Application.StartupPath & "\Drum Samples\Bass Notes\A2 Short.wav^"
        output += Application.StartupPath & "\Drum Samples\Bass Notes\C1 Short.wav^"
        output += Application.StartupPath & "\Drum Samples\Bass Notes\C2 Short.wav^"
        output += Application.StartupPath & "\Drum Samples\Bass Notes\F2 Short.wav^"
        output += Application.StartupPath & "\Drum Samples\Bass Notes\D1 Short.wav^"
        output += Application.StartupPath & "\Drum Samples\Bass Notes\D2 Short.wav^"

        output += Application.StartupPath & "\Drum Samples\Wood Block\Woodblock Single Hit 2.wav^"
        output += Application.StartupPath & "\Drum Samples\High Hats 01\cymbal.wav^"

        output += Application.StartupPath & "\Drum Samples\Tom Set 02\2 Mid Tom.wav^"
        output += Application.StartupPath & "\Drum Samples\Tom Set 03\3 High Tom.wav^"
        output += Application.StartupPath & "\Drum Samples\Tom Set 03\3 Mid Tom.wav^"
        output += Application.StartupPath & "\Drum Samples\Tom Set 03\3 Low Tom.wav^"

        output += Application.StartupPath & "\Drum Samples\Kick Drums 01\tight_kick_017.wav^"
        output += Application.StartupPath & "\Drum Samples\Cymbols\cymbal17.wav^"

        My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\Presets\Bass Guitar.preset", output, False)

    End Sub

    Private Sub CreateWeirdnessPresetFile()

        If File.Exists(Application.StartupPath & "\Presets\Weirdness.preset") Then

            Exit Sub

        End If

        Dim output As String = vbNullString

        'Save the thresholds
        output += "-2.6^-2.8^2.9^1.9^"

        'Save the enabled
        output += "True^True^True^True^"

        'Save the retriggers
        output += "True^True^True^True^"

        output += Application.StartupPath & "\Drum Samples\Weird Sounds\Cemetery Gates.wav^"
        output += Application.StartupPath & "\Drum Samples\Weird Sounds\Meteor_01.wav^"
        output += Application.StartupPath & "\Drum Samples\Weird Sounds\spacey-FX.wav^"
        output += Application.StartupPath & "\Drum Samples\Weird Sounds\24.wav^"
        output += Application.StartupPath & "\Drum Samples\Weird Sounds\CyberSet_001_13.wav^"
        output += Application.StartupPath & "\Drum Samples\Weird Sounds\Elec machine talk 6.wav^"
        output += Application.StartupPath & "\Drum Samples\Weird Sounds\laser_loop_tail.wav^"

        output += Application.StartupPath & "\Drum Samples\Weird Sounds\Vehicle_FX_001_30.wav^"
        output += Application.StartupPath & "\Drum Samples\Weird Sounds\space_fx_loop_23.wav^"

        output += Application.StartupPath & "\Drum Samples\Weird Sounds\Delay Theremin 08.wav^"
        output += Application.StartupPath & "\Drum Samples\Weird Sounds\Industrial_Atmos_06.wav^"
        output += Application.StartupPath & "\Drum Samples\Weird Sounds\FX-121_1.wav^"
        output += Application.StartupPath & "\Drum Samples\Weird Sounds\Dust Clouds On Mars 2.wav^"

        output += Application.StartupPath & "\Drum Samples\Weird Sounds\RetroSciFi_02.wav^"
        output += Application.StartupPath & "\Drum Samples\Weird Sounds\Verb Hit.wav^"

        My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\Presets\Weirdness.preset", output, False)

    End Sub

    ''' <summary>
    ''' Delete Preset File And Remove From Presets
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub DeletePreset()

        Dim filedialog As New OpenFileDialog

        filedialog.InitialDirectory = Application.StartupPath & "\Presets"

        filedialog.Filter = "Preset File .preset |*.preset"

        If filedialog.ShowDialog = Windows.Forms.DialogResult.OK Then

            If filedialog.FileName.EndsWith(".preset") Then

                My.Computer.FileSystem.DeleteFile(filedialog.FileName)

                cmbPreset.Items.Remove(filedialog.SafeFileName.Substring(0, filedialog.SafeFileName.Length - 7))

            Else

                MessageBox.Show("Preset File Not Selected, Operation Aborted", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Warning)

            End If

        End If

    End Sub

    ''' <summary>
    ''' Extract Contents Of Passed In File
    ''' </summary>
    ''' <param name="FullPath"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetFileContents(ByVal FullPath As String) As String

        Dim strContents As String
        Dim objReader As StreamReader
        Try
            objReader = New StreamReader(FullPath)
            strContents = objReader.ReadToEnd()
            objReader.Close()
            Return strContents
        Catch Ex As Exception
            MsgBox("Error reading file " & FullPath)
            Return ""
        End Try
    End Function

    ''' <summary>
    ''' Save Data To File
    ''' </summary>
    ''' <param name="strData"></param>
    ''' <param name="FullPath"></param>
    ''' <remarks></remarks>
    Public Sub SaveTextToFile(ByVal strData As String, ByVal FullPath As String)
        Dim objReader As StreamWriter
        Try
            objReader = New StreamWriter(FullPath)
            objReader.Write(strData)
            objReader.Close()
        Catch Ex As Exception
            MsgBox("Error writing to " & FullPath)
        End Try
    End Sub

    Private Sub btnSavePreset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSavePreset.Click

        Try

            SavePreset()

            LoadPresetsIntoCombobox()

            LoadPreset()

            MessageBox.Show("Preset File: " & cmbPreset.Text & " Saved", "File Save", MessageBoxButtons.OK, MessageBoxIcon.Information)

        Catch ex As Exception

            MessageBox.Show(ex.Message, "File Save Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Sub

    Private Sub cmbPreset_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbPreset.SelectedIndexChanged

        Cursor.Current = Cursors.WaitCursor

        LoadPreset()

        Cursor.Current = Cursors.Default

    End Sub

    '''' <summary>
    '''' The File Paths In The Preset Files Are Intially Set To The Computer That The Project Is Programmed On
    '''' Need To Change All Preset File Paths To The Path Specified At Install
    '''' </summary>
    '''' <remarks></remarks>
    'Private Sub SetPresetFilePathsAccordingToInstallPath()

    '    Dim directory As New DirectoryInfo(Application.StartupPath & "\Presets")

    '    For Each File As FileInfo In directory.GetFiles()

    '        If File.Extension = ".preset" Then



    '        End If

    '    Next File


    'End Sub

    'Andre Knight

#End Region

#Region "Sound Recording Devices"

    Private Sub SetUpInputDevice()

        For Each info As DeviceInformation In devices

            comboboxCaptureDeviceCombo.Items.Add(info.Description)

        Next info

    End Sub

#End Region

#Region "Sound Recording Using DirectX"

    Private Sub OnCreateSoundFile()
        '----------------------------------------------------------------------------- 
        ' Name: OnCreateSoundFile() 
        ' Desc: Called when the user requests to save to a sound file 
        '----------------------------------------------------------------------------- 

        Dim ofd As New SaveFileDialog()
        Dim wf As New WaveFormat()
        Dim result As DialogResult

        ' Get the default media path (something like C:\WINDOWS\MEDIA) 
        If String.Empty = Path Then
            Path = Environment.SystemDirectory.Substring(0, Environment.SystemDirectory.LastIndexOf("\")) + "\media"
        End If

        If Recording Then
            ' Stop the capture and read any data that 
            ' was not caught by a notification 
            StartOrStopRecord(False)
            Recording = False
        End If

        ofd.DefaultExt = ".wav"
        ofd.Filter = "Wave Files|*.wav|All Files|*.*"
        ofd.FileName = FileName
        ofd.InitialDirectory = Path

        ' Update the UI controls to show the sound as loading a file 
        labelFilename.Text = "Saving File..."

        ' Display the OpenFileName dialog. Then, try to load the specified file 
        result = ofd.ShowDialog(Me)

        If DialogResult.Abort = result OrElse DialogResult.Cancel = result Then
            labelFilename.Text = "New Wav File Aborted."
            Return
        End If
        FileName = ofd.FileName

        Try
            CreateRIFF()
        Catch
            labelFilename.Text = "Could Not Create Wave File."
            Return
        End Try

        ' Update the UI controls to show the sound as the file is loaded 
        Dim file As New FileInfo(FileName)
        labelFilename.Text = "File: " & file.Name

        ' Remember the path for next time 
        Path = FileName.Substring(0, FileName.LastIndexOf("\"))
    End Sub

    Private Sub StartOrStopRecord(ByVal StartRecording As Boolean)
        '----------------------------------------------------------------------------- 
        ' Name: StartOrStopRecord() 
        ' Desc: Starts or stops the capture buffer from recording 
        '----------------------------------------------------------------------------- 

        If StartRecording Then
            ' Create a capture buffer, and tell the capture 
            ' buffer to start recording 
            CreateCaptureBuffer()
            applicationBuffer.Start(True)
        Else
            ' Stop the buffer, and read any data that was not 
            ' caught by a notification 
            applicationBuffer.[Stop]()

            RecordCapturedData()

            Writer.Seek(4, SeekOrigin.Begin)
            ' Seek to the length descriptor of the RIFF file. 
            Writer.Write(CInt((SampleCount + 36)))
            ' Write the file length, minus first 8 bytes of RIFF description. 
            Writer.Seek(40, SeekOrigin.Begin)
            ' Seek to the data length descriptor of the RIFF file. 
            Writer.Write(SampleCount)
            ' Write the length of the sample data in bytes. 
            Writer.Close()
            ' Close the file now. 
            Writer = Nothing
            ' Set the writer to null. 
            ' Set the FileStream to null. 
            WaveFile = Nothing
        End If
    End Sub

    Private Sub CreateRIFF()
        '************************************************************************* 
        ' 
        ' Here is where the file will be created. A 
        ' wave file is a RIFF file, which has chunks 
        ' of data that describe what the file contains. 
        ' A wave RIFF file is put together like this: 
        ' 
        ' The 12 byte RIFF chunk is constructed like this: 
        ' Bytes 0 - 3 : 'R' 'I' 'F' 'F' 
        ' Bytes 4 - 7 : Length of file, minus the first 8 bytes of the RIFF description. 
        ' (4 bytes for "WAVE" + 24 bytes for format chunk length + 
        ' 8 bytes for data chunk description + actual sample data size.) 
        ' Bytes 8 - 11: 'W' 'A' 'V' 'E' 
        ' 
        ' The 24 byte FORMAT chunk is constructed like this: 
        ' Bytes 0 - 3 : 'f' 'm' 't' ' ' 
        ' Bytes 4 - 7 : The format chunk length. This is always 16. 
        ' Bytes 8 - 9 : File padding. Always 1. 
        ' Bytes 10- 11: Number of channels. Either 1 for mono, or 2 for stereo. 
        ' Bytes 12- 15: Sample rate. 
        ' Bytes 16- 19: Number of bytes per second. 
        ' Bytes 20- 21: Bytes per sample. 1 for 8 bit mono, 2 for 8 bit stereo or 
        ' 16 bit mono, 4 for 16 bit stereo. 
        ' Bytes 22- 23: Number of bits per sample. 
        ' 
        ' The DATA chunk is constructed like this: 
        ' Bytes 0 - 3 : 'd' 'a' 't' 'a' 
        ' Bytes 4 - 7 : Length of data, in bytes. 
        ' Bytes 8 -...: Actual sample data. 
        ' 
        ' ************************************************************************** 


        ' Open up the wave file for writing. 
        WaveFile = New FileStream(FileName, FileMode.Create)
        Writer = New BinaryWriter(WaveFile)

        ' Set up file with RIFF chunk info. 
        Dim ChunkRiff As Char() = {"R"c, "I"c, "F"c, "F"c}
        Dim ChunkType As Char() = {"W"c, "A"c, "V"c, "E"c}
        Dim ChunkFmt As Char() = {"f"c, "m"c, "t"c, " "c}
        Dim ChunkData As Char() = {"d"c, "a"c, "t"c, "a"c}

        Dim shPad As Short = 1
        ' File padding 
        Dim nFormatChunkLength As Integer = 16
        ' Format chunk length. 
        Dim nLength As Integer = 0
        ' File length, minus first 8 bytes of RIFF description. This will be filled in later. 
        Dim shBytesPerSample As Short = 0
        ' Bytes per sample. 
        ' Figure out how many bytes there will be per sample. 
        If 8 = InputFormat.BitsPerSample AndAlso 1 = InputFormat.Channels Then
            shBytesPerSample = 1
        ElseIf (8 = InputFormat.BitsPerSample AndAlso 2 = InputFormat.Channels) OrElse (16 = InputFormat.BitsPerSample AndAlso 1 = InputFormat.Channels) Then
            shBytesPerSample = 2
        ElseIf 16 = InputFormat.BitsPerSample AndAlso 2 = InputFormat.Channels Then
            shBytesPerSample = 4
        End If

        ' Fill in the riff info for the wave file. 
        Writer.Write(ChunkRiff)
        Writer.Write(nLength)
        Writer.Write(ChunkType)

        ' Fill in the format info for the wave file. 
        Writer.Write(ChunkFmt)
        Writer.Write(nFormatChunkLength)
        Writer.Write(shPad)
        Writer.Write(InputFormat.Channels)
        Writer.Write(InputFormat.SamplesPerSecond)
        Writer.Write(InputFormat.AverageBytesPerSecond)
        Writer.Write(shBytesPerSample)
        Writer.Write(InputFormat.BitsPerSample)

        ' Now fill in the data chunk. 
        Writer.Write(ChunkData)
        Writer.Write(CInt(0))
        ' The sample length will be written in later. 
    End Sub

    Private Sub CreateCaptureBuffer()
        '----------------------------------------------------------------------------- 
        ' Name: CreateCaptureBuffer() 
        ' Desc: Creates a capture buffer and sets the format 
        '----------------------------------------------------------------------------- 
        Dim dscheckboxd As New CaptureBufferDescription()

        If applicationNotify IsNot Nothing Then
            applicationNotify.Dispose()
            applicationNotify = Nothing
        End If
        If applicationBuffer IsNot Nothing Then
            applicationBuffer.Dispose()
            applicationBuffer = Nothing
        End If

        If 0 = InputFormat.Channels Then
            Return
        End If

        ' Set the notification size 
        NotifySize = IIf((1024 > InputFormat.AverageBytesPerSecond / 8), 1024, (InputFormat.AverageBytesPerSecond / 8))
        NotifySize -= NotifySize Mod InputFormat.BlockAlign

        ' Set the buffer sizes 
        CaptureBufferSize = NotifySize * NumberRecordNotifications

        ' Create the capture buffer 
        dscheckboxd.BufferBytes = CaptureBufferSize
        InputFormat.FormatTag = WaveFormatTag.Pcm
        dscheckboxd.Format = InputFormat
        ' Set the format during creatation 
        applicationBuffer = New CaptureBuffer(dscheckboxd, applicationDevice)
        NextCaptureOffset = 0

        InitNotifications()

    End Sub

    Private Sub InitNotifications()
        '----------------------------------------------------------------------------- 
        ' Name: InitNotifications() 
        ' Desc: Inits the notifications on the capture buffer which are handled 
        ' in the notify thread. 
        '----------------------------------------------------------------------------- 

        If applicationBuffer Is Nothing Then
            Throw New NullReferenceException()
        End If

        ' Create a thread to monitor the notify events 
        If NotifyThread Is Nothing Then
            NotifyThread = New Thread(New ThreadStart(AddressOf WaitThread))
            Capturing = True
            NotifyThread.Start()

            ' Create a notification event, for when the sound stops playing 
            NotificationEvent = New AutoResetEvent(False)
        End If
        For i As Integer = 0 To NumberRecordNotifications - 1


            ' Setup the notification positions 
            PositionNotify(i).Offset = (NotifySize * i) + NotifySize - 1
            PositionNotify(i).EventNotifyHandle = NotificationEvent.Handle
        Next

        applicationNotify = New Notify(applicationBuffer)

        ' Tell DirectSound when to notify the app. The notification will come in the from 
        ' of signaled events that are handled in the notify thread. 
        applicationNotify.SetNotificationPositions(PositionNotify, NumberRecordNotifications)
    End Sub

    Private Sub RecordCapturedData()
        '----------------------------------------------------------------------------- 
        ' Name: RecordCapturedData() 
        ' Desc: Copies data from the capture buffer to the output buffer 
        '----------------------------------------------------------------------------- 
        Dim CaptureData As Byte() = Nothing
        Dim ReadPos As Integer
        Dim CapturePos As Integer
        Dim LockSize As Integer

        applicationBuffer.GetCurrentPosition(CapturePos, ReadPos)
        LockSize = ReadPos - NextCaptureOffset
        If LockSize < 0 Then
            LockSize += CaptureBufferSize
        End If

        ' Block align lock size so that we are always write on a boundary 
        LockSize -= (LockSize Mod NotifySize)

        If 0 = LockSize Then
            Return
        End If

        ' Read the capture buffer. 
        CaptureData = applicationBuffer.Read(NextCaptureOffset, GetType(Byte), LockFlag.None, LockSize)

        ' Write the data into the wav file 
        Writer.Write(CaptureData, 0, CaptureData.Length)

        ' Update the number of samples, in bytes, of the file so far. 
        SampleCount += CaptureData.Length

        ' Move the capture offset along 
        NextCaptureOffset += CaptureData.Length
        NextCaptureOffset = NextCaptureOffset Mod CaptureBufferSize
        ' Circular buffer 
    End Sub

    Private Sub WaitThread()
        While Capturing
            'Sit here and wait for a message to arrive 
            NotificationEvent.WaitOne(Timeout.Infinite, True)
            RecordCapturedData()
        End While
    End Sub

#End Region

#Region "Sound Formats"

    Private Sub InitDirectSound()

        CaptureBufferSize = 0
        NotifySize = 0

        ' Create DirectSound.Capture using the preferred capture device 
        Try
            applicationDevice = New Capture(CaptureDeviceGuid)
        Catch
        End Try
    End Sub

    Private Sub GetWaveFormatFromIndex(ByVal Index As Integer, ByRef format As WaveFormat)
        '----------------------------------------------------------------------------- 
        ' Name: GetWaveFormatFromIndex() 
        ' Desc: Returns 20 different wave formats based on Index 
        '----------------------------------------------------------------------------- 
        Dim SampleRate As Integer = Index / 4
        Dim iType As Integer = Index Mod 4

        Select Case SampleRate
            Case 0
                format.SamplesPerSecond = 48000
                Exit Select
            Case 1
                format.SamplesPerSecond = 44100
                Exit Select
            Case 2
                format.SamplesPerSecond = 22050
                Exit Select
            Case 3
                format.SamplesPerSecond = 11025
                Exit Select
            Case 4
                format.SamplesPerSecond = 8000
                Exit Select
        End Select

        Select Case iType
            Case 0
                format.BitsPerSample = 8
                format.Channels = 1
                Exit Select
            Case 1
                format.BitsPerSample = 16
                format.Channels = 1
                Exit Select
            Case 2
                format.BitsPerSample = 8
                format.Channels = 2
                Exit Select
            Case 3
                format.BitsPerSample = 16
                format.Channels = 2
                Exit Select
        End Select

        format.BlockAlign = CShort((format.Channels * (format.BitsPerSample / 8)))
        format.AverageBytesPerSecond = format.BlockAlign * format.SamplesPerSecond

    End Sub

    Private Sub FillFormatListBox()
        '----------------------------------------------------------------------------- 
        ' Name: FillFormatListBox() 
        ' Desc: Fills the format list box based on the availible formats 
        '----------------------------------------------------------------------------- 
        Dim info As New FormatInfo()
        Dim strFormatName As String = String.Empty
        Dim format As New WaveFormat()
        For iIndex As Integer = 0 To InputFormatSupported.Length - 1

            If InputFormatSupported(iIndex) Then
                ' Turn the index into a WaveFormat then turn that into a 
                ' string and put the string in the listbox 
                GetWaveFormatFromIndex(iIndex, format)
                info.format = format
                formats.Add(info)
            End If
        Next
        cboFormatsInputListbox.DataSource = formats
    End Sub

    Private Shared Function ConvertWaveFormatToString(ByVal format As WaveFormat) As String
        '----------------------------------------------------------------------------- 
        ' Name: ConvertWaveFormatToString() 
        ' Desc: Converts a wave format to a text string 
        '----------------------------------------------------------------------------- 
        Return format.SamplesPerSecond.ToString() + " Hz, " + format.BitsPerSample.ToString() + "-bit " + (IIf((format.Channels = 1), "Mono", "Stereo"))

    End Function

    Private Structure FormatInfo

        Public format As WaveFormat

        Public Overloads Overrides Function ToString() As String

            Return ConvertWaveFormatToString(format)

        End Function

    End Structure

    Private Sub FormatsOK()
        '----------------------------------------------------------------------------- 
        ' Name: FormatsOK() 
        ' Desc: Stores the capture buffer format based on what was selected 
        '----------------------------------------------------------------------------- 

        InputFormat = DirectCast(formats(cboFormatsInputListbox.SelectedIndex), FormatInfo).format
        'Me.DialogResult = DialogResult.OK
        'Close()
    End Sub

    Private Sub ScanAvailableInputFormats()
        '----------------------------------------------------------------------------- 
        ' Name: ScanAvailableInputFormats() 
        ' Desc: Tests to see if 20 different standard wave formats are supported by 
        ' the capture device 
        '----------------------------------------------------------------------------- 
        Dim format As New WaveFormat()
        Dim dscheckboxd As New CaptureBufferDescription()
        Dim pDSCaptureBuffer As CaptureBuffer = Nothing

        ' This might take a second or two, so throw up the hourglass 
        Cursor = Cursors.WaitCursor

        format.FormatTag = WaveFormatTag.Pcm
        For iIndex As Integer = 0 To 19

            ' Try 20 different standard formats to see if they are supported 
            GetWaveFormatFromIndex(iIndex, format)

            ' To test if a capture format is supported, try to create a 
            ' new capture buffer using a specific format. If it works 
            ' then the format is supported, otherwise not. 
            dscheckboxd.BufferBytes = format.AverageBytesPerSecond
            dscheckboxd.Format = format

            Try
                pDSCaptureBuffer = New CaptureBuffer(dscheckboxd, applicationDevice)
                InputFormatSupported(iIndex) = True
            Catch
                InputFormatSupported(iIndex) = False
            End Try
            If pDSCaptureBuffer IsNot Nothing Then
                pDSCaptureBuffer.Dispose()
            End If
        Next
        Cursor = Cursors.[Default]
    End Sub

#End Region

#Region "Browse Buttons"

    Private Sub btnSetSoundLeftRight1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundLeftRight1.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundLeftRight1 = soundbank.addSound(f.FileName)
            lblSoundLeftRight1.Text = f.SafeFileName
            'btnGroup1SetSoundA.Text = f.FileName
        End If

    End Sub

    Private Sub btnSetSoundLeftRight2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundLeftRight2.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundLeftRight2 = soundbank.addSound(f.FileName)
            lblSoundLeftRight2.Text = f.SafeFileName
            'btnGroup1SetSoundA.Text = f.FileName
        End If

    End Sub

    Private Sub btnSetSoundLeftRightWithA1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundLeftRightWithA1.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundLeftRightWithA1 = soundbank.addSound(f.FileName)
            lblSoundLeftRightWithA1.Text = f.SafeFileName
            'btnGroup1SetSoundB.Text = f.FileName
        End If

    End Sub

    Private Sub btnSetSoundLeftRightWithA2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundLeftRightWithA2.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundLeftRightWithA2 = soundbank.addSound(f.FileName)
            lblSoundLeftRightWithA2.Text = f.SafeFileName
            'btnGroup1SetSoundB.Text = f.FileName
        End If

    End Sub

    Private Sub btnSetSoundDown1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundDown1.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundDown1 = soundbank.addSound(f.FileName)
            lblSoundDown1.Text = f.SafeFileName
            'btnGroup2SetSoundC.Text = f.FileName
        End If

    End Sub

    Private Sub btnSetSoundDown2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundDown2.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundDown2 = soundbank.addSound(f.FileName)
            lblSoundDown2.Text = f.SafeFileName
            'btnGroup2SetSoundC.Text = f.FileName
        End If

    End Sub

    Private Sub btnSetSoundNunchuk1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundNunchuk1.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundNunchuk1 = soundbank.addSound(f.FileName)
            lblSoundNunchuk1.Text = f.SafeFileName
            'btnGroup3SetSoundD.Text = f.FileName
        End If

    End Sub

    Private Sub btnSetSoundNunchukWithC1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundNunchukWithC1.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundNunchukWithC1 = soundbank.addSound(f.FileName)
            lblSoundNunchukWithC1.Text = f.SafeFileName
            'btnGroup3SetSoundE.Text = f.FileName
        End If

    End Sub

    Private Sub btnSetSoundNunchukWithZ1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundNunchukWithZ1.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundNunchukWithZ1 = soundbank.addSound(f.FileName)
            lblSoundNunchukWithZ1.Text = f.SafeFileName
            'btnGroup3SetSoundE.Text = f.FileName
        End If

    End Sub

    Private Sub btnSetSoundNunchuk2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundNunchuk2.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundNunchuk2 = soundbank.addSound(f.FileName)
            lblSoundNunchuk2.Text = f.SafeFileName
            'btnGroup3SetSoundD.Text = f.FileName
        End If

    End Sub

    Private Sub btnSetSoundNunchukWithC2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundNunchukWithC2.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundNunchukWithC2 = soundbank.addSound(f.FileName)
            lblSoundNunchukWithC2.Text = f.SafeFileName
            'btnGroup3SetSoundE.Text = f.FileName
        End If

    End Sub

    Private Sub btnSetSoundNunchukWithZ2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundNunchukWithZ2.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundNunchukWithZ2 = soundbank.addSound(f.FileName)
            lblSoundNunchukWithZ2.Text = f.SafeFileName
            'btnGroup3SetSoundE.Text = f.FileName
        End If

    End Sub

    Private Sub btnSetSoundForwardAndDown1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundForwardAndDown1.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundForwardAndDown1 = soundbank.addSound(f.FileName)
            lblSoundForwardAndDown1.Text = f.SafeFileName
            'btnGroup4SetSoundF.Text = f.FileName
        End If

    End Sub

    Private Sub btnSetSoundForwardAndDown2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundForwardAndDown2.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundForwardAndDown2 = soundbank.addSound(f.FileName)
            lblSoundForwardAndDown2.Text = f.SafeFileName
            'btnGroup4SetSoundF.Text = f.FileName
        End If

    End Sub

    Private Sub btnSetSoundForwardAndDownWithA1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundForwardAndDownWithA1.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundForwardAndDownWithA1 = soundbank.addSound(f.FileName)
            lblSoundForwardAndDownWithA1.Text = f.SafeFileName
            'btnGroup4SetSoundG.Text = f.FileName
        End If

    End Sub

    Private Sub btnSetSoundForwardAndDownWithA2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundForwardAndDownWithA2.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundForwardAndDownWithA2 = soundbank.addSound(f.FileName)
            lblSoundForwardAndDownWithA2.Text = f.SafeFileName
            'btnGroup4SetSoundG.Text = f.FileName
        End If

    End Sub

    Private Sub btnSetSoundForwardAndDownWithB2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundForwardAndDownWithB2.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundForwardAndDownWithB2 = soundbank.addSound(f.FileName)
            lblSoundForwardAndDownWithB2.Text = f.SafeFileName
            'btnGroup4SetSoundG.Text = f.FileName
        End If

    End Sub

    Private Sub btnSetSoundForwardAndDownWithMinus2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundForwardAndDownWithMinus2.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundForwardAndDownWithMinus2 = soundbank.addSound(f.FileName)
            lblSoundForwardAndDownWithMinus2.Text = f.SafeFileName
        End If

    End Sub

    Private Sub btnSetSoundForwardAndDownWithHome2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundForwardAndDownWithHome2.Click


        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundForwardAndDownWithHome2 = soundbank.addSound(f.FileName)
            lblSoundForwardAndDownWithHome2.Text = f.SafeFileName
            'btnGroup4SetSoundG.Text = f.FileName
        End If
    End Sub

    Private Sub btnSetSoundForwardAndDownWithLeft1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundForwardAndDownWithLeft1.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundForwardAndDownWithLeft1 = soundbank.addSound(f.FileName)
            lblSoundForwardAndDownWithLeft1.Text = f.SafeFileName
            'btnGroup5SetSoundLeft.Text = f.FileName
        End If

    End Sub

    Private Sub btnSetSoundForwardAndDownWithLeft2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundForwardAndDownWithLeft2.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundForwardAndDownWithLeft2 = soundbank.addSound(f.FileName)
            lblSoundForwardAndDownWithLeft2.Text = f.SafeFileName
            'btnGroup5SetSoundLeft.Text = f.FileName
        End If

    End Sub

    Private Sub btnSetSoundForwardAndDownWithUp1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundForwardAndDownWithUp1.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundForwardAndDownWithUp1 = soundbank.addSound(f.FileName)
            lblSoundForwardAndDownWithUp1.Text = f.SafeFileName
            'btnGroup5SetSoundUp.Text = f.FileName
        End If

    End Sub

    Private Sub btnSetSoundForwardAndDownWithUp2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundForwardAndDownWithUp2.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundForwardAndDownWithUp2 = soundbank.addSound(f.FileName)
            lblSoundForwardAndDownWithUp2.Text = f.SafeFileName
            'btnGroup5SetSoundUp.Text = f.FileName
        End If

    End Sub

    Private Sub btnSetSoundForwardAndDownWithRight1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundForwardAndDownWithRight1.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundForwardAndDownWithRight1 = soundbank.addSound(f.FileName)
            lblSoundForwardAndDownWithRight1.Text = f.SafeFileName
            'btnGroup5SetSoundRight.Text = f.FileName
        End If

    End Sub

    Private Sub btnSetSoundForwardAndDownWithRight2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundForwardAndDownWithRight2.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundForwardAndDownWithRight2 = soundbank.addSound(f.FileName)
            lblSoundForwardAndDownWithRight2.Text = f.SafeFileName
            'btnGroup5SetSoundRight.Text = f.FileName
        End If

    End Sub

    Private Sub btnSetSoundForwardAndDownWithDown1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundForwardAndDownWithDown1.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundForwardAndDownWithDown1 = soundbank.addSound(f.FileName)
            lblSoundForwardAndDownWithDown1.Text = f.SafeFileName
            'btnGroup5SetSoundDown.Text = f.FileName
        End If

    End Sub

    Private Sub btnSetSoundForwardAndDownWithDown2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundForwardAndDownWithDown2.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundForwardAndDownWithDown2 = soundbank.addSound(f.FileName)
            lblSoundForwardAndDownWithDown2.Text = f.SafeFileName
            'btnGroup5SetSoundDown.Text = f.FileName
        End If

    End Sub

    Private Sub btnSetSoundForwardAndDownWithB1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundForwardAndDownWithB1.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundForwardAndDownWithB1 = soundbank.addSound(f.FileName)
            lblSoundForwardAndDownWithB1.Text = f.SafeFileName
        End If

    End Sub

    Private Sub btnSetSoundForwardAndDownWithMinus1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundForwardAndDownWithMinus1.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundForwardAndDownWithMinus1 = soundbank.addSound(f.FileName)
            lblSoundForwardAndDownWithMinus1.Text = f.SafeFileName
        End If

    End Sub

    Private Sub btnSetSoundForwardAndDownWithPlus2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundForwardAndDownWithPlus2.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundForwardAndDownWithPlus2 = soundbank.addSound(f.FileName)
            lblSoundForwardAndDownWithPlus2.Text = f.SafeFileName
        End If

    End Sub

    Private Sub btnSetSoundForwardAndDownWithHome1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundForwardAndDownWithHome1.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundForwardAndDownWithHome1 = soundbank.addSound(f.FileName)
            lblSoundForwardAndDownWithHome1.Text = f.SafeFileName
        End If

    End Sub

    Private Sub btn2SetSoundButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        'Dim f As New OpenFileDialog
        'f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        'f.Filter = ".wav files|*.wav;"
        'If f.ShowDialog = Windows.Forms.DialogResult.OK Then
        '    buttonOneFile2 = soundbank.addSound(f.FileName)
        '    lbl2ButtonOne.Text = f.SafeFileName
        'End If

    End Sub

    Private Sub btnSetSoundForwardAndDownWithPlus1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSoundForwardAndDownWithPlus1.Click

        Dim f As New OpenFileDialog
        f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        f.Filter = ".wav files|*.wav;"
        If f.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundForwardAndDownWithPlus1 = soundbank.addSound(f.FileName)
            lblSoundForwardAndDownWithPlus1.Text = f.SafeFileName
        End If

    End Sub

    Private Sub btn2SetSoundButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        'Dim f As New OpenFileDialog
        'f.InitialDirectory = Application.StartupPath & "\Drum Samples"
        'f.Filter = ".wav files|*.wav;"
        'If f.ShowDialog = Windows.Forms.DialogResult.OK Then
        '    buttonTwoFile2 = soundbank.addSound(f.FileName)
        '    lbl2ButtonTwo.Text = f.SafeFileName
        'End If

    End Sub

#End Region

#Region "Play Sound Buttons"

    Private Sub btnPlaySoundLeftRight1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundLeftRight1.Click
        soundbank.startSound(SoundLeftRight1, False)
    End Sub

    Private Sub btnPlaySoundLeftRight2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundLeftRight2.Click
        soundbank.startSound(SoundLeftRight2, False)
    End Sub

    Private Sub btnPlaySoundLeftRightWithA1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundLeftRightWithA1.Click
        soundbank.startSound(SoundLeftRightWithA1, False)
    End Sub

    Private Sub btnPlaySoundLeftRightWithA2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundLeftRightWithA2.Click
        soundbank.startSound(SoundLeftRightWithA2, False)
    End Sub

    Private Sub btnPlaySoundDown1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundDown1.Click
        soundbank.startSound(SoundDown1, False)
    End Sub

    Private Sub btnPlaySoundDown2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundDown2.Click
        soundbank.startSound(SoundDown2, False)
    End Sub

    Private Sub btnPlaySoundNunchuk1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundNunchuk1.Click
        soundbank.startSound(SoundNunchuk1, False)
    End Sub

    Private Sub btnPlaySoundNunchukWithC1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundNunchukWithC1.Click
        soundbank.startSound(SoundNunchukWithC1, False)
    End Sub

    Private Sub btnPlaySoundNunchukWithZ1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundNunchukWithZ1.Click
        soundbank.startSound(SoundNunchukWithZ1, False)
    End Sub

    Private Sub btnPlaySoundNunchuk2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundNunchuk2.Click
        soundbank.startSound(SoundNunchuk2, False)
    End Sub

    Private Sub btnPlaySoundNunchukWithC2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundNunchukWithC2.Click
        soundbank.startSound(SoundNunchukWithC2, False)
    End Sub

    Private Sub btnPlaySoundNunchukWithZ2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundNunchukWithZ2.Click
        soundbank.startSound(SoundNunchukWithZ2, False)
    End Sub

    Private Sub btnPlaySoundForwardAndDown1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundForwardAndDown1.Click
        soundbank.startSound(SoundForwardAndDown1, False)
    End Sub

    Private Sub btnPlaySoundForwardAndDownWithA1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundForwardAndDownWithA1.Click
        soundbank.startSound(SoundForwardAndDownWithA1, False)
    End Sub

    Private Sub btnPlaySoundForwardAndDownWithB1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundForwardAndDownWithB1.Click
        soundbank.startSound(SoundForwardAndDownWithB1, False)
    End Sub

    Private Sub btnPlaySoundForwardAndDownWithMinus1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundForwardAndDownWithMinus1.Click
        soundbank.startSound(SoundForwardAndDownWithMinus1, False)
    End Sub

    Private Sub btnPlaySoundForwardAndDownWithHome1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundForwardAndDownWithHome1.Click
        soundbank.startSound(SoundForwardAndDownWithHome1, False)
    End Sub

    Private Sub btnPlaySoundForwardAndDownWithPlus1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundForwardAndDownWithPlus1.Click
        soundbank.startSound(SoundForwardAndDownWithPlus1, False)
    End Sub

    Private Sub btnPlaySoundForwardAndDownWithUp1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundForwardAndDownWithUp1.Click
        soundbank.startSound(SoundForwardAndDownWithUp1, False)
    End Sub

    Private Sub btnPlaySoundForwardAndDownWithDown1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundForwardAndDownWithDown1.Click
        soundbank.startSound(SoundForwardAndDownWithDown1, False)
    End Sub

    Private Sub btnPlaySoundForwardAndDownWithLeft1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundForwardAndDownWithLeft1.Click
        soundbank.startSound(SoundForwardAndDownWithLeft1, False)
    End Sub

    Private Sub btnPlaySoundForwardAndDownWithRight1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundForwardAndDownWithRight1.Click
        soundbank.startSound(SoundForwardAndDownWithRight1, False)
    End Sub

    Private Sub btnPlaySoundForwardAndDown2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundForwardAndDown2.Click
        soundbank.startSound(SoundForwardAndDown2, False)
    End Sub

    Private Sub btnPlaySoundForwardAndDownWithA2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundForwardAndDownWithA2.Click
        soundbank.startSound(SoundForwardAndDownWithA2, False)
    End Sub

    Private Sub btnPlaySoundForwardAndDownWithB2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundForwardAndDownWithB2.Click
        soundbank.startSound(SoundForwardAndDownWithB2, False)
    End Sub

    Private Sub btnPlaySoundForwardAndDownWithMinus2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundForwardAndDownWithMinus2.Click
        soundbank.startSound(SoundForwardAndDownWithMinus2, False)
    End Sub

    Private Sub btnPlaySoundForwardAndDownWithHome2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundForwardAndDownWithHome2.Click
        soundbank.startSound(SoundForwardAndDownWithHome2, False)
    End Sub

    Private Sub btnPlaySoundForwardAndDownWithPlus2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundForwardAndDownWithPlus2.Click
        soundbank.startSound(SoundForwardAndDownWithPlus2, False)
    End Sub

    Private Sub btnPlaySoundForwardAndDownWithUp2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundForwardAndDownWithUp2.Click
        soundbank.startSound(SoundForwardAndDownWithUp2, False)
    End Sub

    Private Sub btnPlaySoundForwardAndDownWithDown2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundForwardAndDownWithDown2.Click
        soundbank.startSound(SoundForwardAndDownWithDown2, False)
    End Sub

    Private Sub btnPlaySoundForwardAndDownWithLeft2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundForwardAndDownWithLeft2.Click
        soundbank.startSound(SoundForwardAndDownWithLeft2, False)
    End Sub

    Private Sub btnPlaySoundForwardAndDownWithRight2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySoundForwardAndDownWithRight2.Click
        soundbank.startSound(SoundForwardAndDownWithRight2, False)
    End Sub

#End Region

#Region "Slider Code"

    Private Sub tbMinX_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tb1MinX.Scroll
        xMinThresh1 = tb1MinX.Value / 10
        lbl1MinXThresh.Text = xMinThresh1
    End Sub

    Private Sub tb2MinX_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tb2MinX.Scroll
        xMinThresh2 = tb2MinX.Value / 10
        lbl2MinXThresh.Text = xMinThresh2
    End Sub

    Private Sub tbMaxZ_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tb1MaxZ.Scroll
        zMaxThresh1 = tb1MaxZ.Value / 10
        lbl1MaxZThresh.Text = zMaxThresh1
    End Sub

    Private Sub tb2MaxZ_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tb2MaxZ.Scroll

        zMaxThresh2 = tb2MaxZ.Value / 10
        lbl2MaxZThresh.Text = zMaxThresh2

    End Sub

    Private Sub tbMinY_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tb1MinY.Scroll
        yMinThresh1 = tb1MinY.Value / 10
        lbl1MinYThresh.Text = yMinThresh1
    End Sub

    Private Sub tb2MinY_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tb2MinY.Scroll

        yMinThresh2 = tb2MinY.Value / 10
        lbl2MinYThresh.Text = yMinThresh2

    End Sub

    Private Sub tbNunchuk_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tb1Nunchuk.Scroll
        nunchukThresh1 = tb1Nunchuk.Value / 10.0
        lbl1NunchukThresh.Text = nunchukThresh1
    End Sub

    Private Sub tb2Nunchuk_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tb2Nunchuk.Scroll

        nunchukThresh2 = tb2Nunchuk.Value / 10.0
        lbl2NunchukThresh.Text = nunchukThresh2

    End Sub

#End Region

    Private Sub frmWiiDrums_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        SetApplicationVersion()

        LoadSettings()

        SetNumberOfTabPages()

        SetNumberOfBatteryLevelsToShow()

        CreateProgramPresetFiles()

        If StartUpSoundToolStripMenuItem.Checked Then
            PlayStartUpSound()
        End If

        'Start Form Fade In Effect
        tmrFade.Enabled = True

    End Sub

    Private Sub SetApplicationVersion()

        Me.Text += " version: " & Application.ProductVersion()

    End Sub

    Private Sub LoadSettings()

        Try

            If Not File.Exists(Application.StartupPath & "\Settings.txt") Then CreateSettingsFile()

            Dim streamreader As New StreamReader(Application.StartupPath & "\Settings.txt")

            Dim readstring As String = streamreader.ReadLine()

            Dim propertysetting As String = String.Empty

            If readstring.Contains(":") Then

                propertysetting = readstring.Substring(0, readstring.IndexOf(":"))

            Else

                propertysetting = String.Empty

            End If

            Dim soundfilename As String = String.Empty

            While readstring <> String.Empty

                Select Case propertysetting

                    Case "PlayStartUpSound"

                        StartUpSoundToolStripMenuItem.Checked = CBool(readstring.Substring(readstring.IndexOf(":") + 2))

                End Select

                readstring = streamreader.ReadLine()

            End While

        Catch ex As Exception

            MessageBox.Show(ex.Message, "Load Settings File Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Sub

    Private Sub CreateSettingsFile()

        Dim output As String = String.Empty

        Try

            output += "PlayStartUpSound: True" & vbCrLf

            My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\Settings.txt", output, False)

        Catch ex As Exception

            MessageBox.Show(ex.Message, "Create Settings File Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Sub

    Private Sub SaveSettings()

        Dim output As String = String.Empty

        Try

            output += "PlayStartUpSound: " & StartUpSoundToolStripMenuItem.Checked & vbCrLf

            My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\Settings.txt", output, False)

        Catch ex As Exception

            MessageBox.Show(ex.Message, "Save Settings File Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Sub

    Private Sub SetNumberOfTabPages()

        If Wiimote_Collection.Count = 1 Then

            Dim tpc As New List(Of TabPage)

            'Since MS hasn't given the functionality to hide tab pages, Move the Tabpage To A  Hidden Container
            tpc.Add(TabControl1.TabPages(1))
            TabControl1.TabPages.RemoveAt(1)

            'Move the Tabpage from the hidden container back to the tabcontrol
            'TabControl1.TabPages.Insert(1, tpc(0))
            'tpc.RemoveAt(0)

        End If

    End Sub

    Private Sub SetNumberOfBatteryLevelsToShow()

        If Wiimote_Collection.Count = 1 Then

            'If only 1 wiimote connected, then hide wiimote 2 battery controls
            lblWiimote2Label.Visible = False
            pbWiimote2Battery.Visible = False
            lblWiimote2Battery.Visible = False

            'Move wiimote 1 battery controls to wiimote 2 battery controls position - so it looks nice
            lblWiimote1Label.Location = New System.Drawing.Point(lblWiimote2Label.Location.X, lblWiimote2Label.Location.Y)
            pbWiimote1Battery.Location = New System.Drawing.Point(pbWiimote2Battery.Location.X, pbWiimote2Battery.Location.Y)
            lblWiimote1Battery.Location = New System.Drawing.Point(lblWiimote2Battery.Location.X, lblWiimote2Battery.Location.Y)

        End If

    End Sub

    Private Sub SetWiimoteObjects()

        If Wiimote_Collection.Count = 1 Then

            wiimote1 = Wiimote_Collection(0)

        Else

            wiimote1 = Wiimote_Collection(0)

            wiimote2 = Wiimote_Collection(1)

        End If

    End Sub

    Private Sub PlayStartUpSound()

        My.Computer.Audio.Play(My.Resources.Intro1, AudioPlayMode.Background)

    End Sub

    ''' <summary>
    ''' Start Procedure For Main Form
    ''' </summary>
    Private Sub Start()

        Try

            'Initialize SoundBank
            soundbank = New SoundBank(Me)

            SetUpOutputDevice()

            '*********************************
            'Recording Intialization Methods
            InitDirectSound()
            SetUpInputDevice()
            CreateCaptureBuffer()
            '*********************************

            LoadPresetsIntoCombobox()

            IntializeVariables()

            SetToolTips()

            SetWiimoteObjects()

            'Intialize Preset To Use On Startup
            cmbPreset.SelectedText = "Standard Drum Kit"

            LoadPreset()

        Catch ex As Exception

            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Sub

    Private Sub IntializeVariables()

        'Wiimote 1
        x1 = 0.0
        y1 = 0.0
        z1 = 0.0
        nunchuk1 = 0.0

        xMinThresh1 = tb1MinX.Value / 10.0
        lbl1MinXThresh.Text = xMinThresh1
        zMaxThresh1 = tb1MaxZ.Value / 10.0
        lbl1MaxZThresh.Text = zMaxThresh1
        yMinThresh1 = tb1MinY.Value / 10.0
        lbl1MinYThresh.Text = yMinThresh1
        nunchukThresh1 = tb1Nunchuk.Value / 10.0
        lbl1NunchukThresh.Text = nunchukThresh1

        SoundLeftRight1 = -1
        SoundLeftRightWithA1 = -1
        SoundDown1 = -1
        SoundForwardAndDown1 = -1
        SoundForwardAndDownWithA1 = -1
        SoundForwardAndDownWithB1 = -1
        SoundForwardAndDownWithLeft1 = -1
        SoundForwardAndDownWithRight1 = -1
        SoundForwardAndDownWithUp1 = -1
        SoundForwardAndDownWithDown1 = -1
        SoundForwardAndDownWithMinus1 = -1
        SoundForwardAndDownWithHome1 = -1
        SoundForwardAndDownWithPlus1 = -1
        SoundNunchuk1 = -1
        SoundNunchukWithC1 = -1
        SoundNunchukWithZ1 = -1

        'Wiimote 2
        x2 = 0.0
        y2 = 0.0
        z2 = 0.0
        nunchuk2 = 0.0

        xMinThresh2 = tb2MinX.Value / 10.0
        lbl2MinXThresh.Text = xMinThresh2
        zMaxThresh2 = tb2MaxZ.Value / 10.0
        lbl2MaxZThresh.Text = zMaxThresh2
        yMinThresh2 = tb2MinY.Value / 10.0
        lbl2MinYThresh.Text = yMinThresh2
        nunchukThresh2 = tb2Nunchuk.Value / 10.0
        lbl2NunchukThresh.Text = nunchukThresh2

        SoundLeftRight2 = -1
        SoundLeftRightWithA2 = -1
        SoundDown2 = -1
        SoundForwardAndDown2 = -1
        SoundForwardAndDownWithA2 = -1
        SoundForwardAndDownWithB2 = -1
        SoundForwardAndDownWithLeft2 = -1
        SoundForwardAndDownWithRight2 = -1
        SoundForwardAndDownWithUp2 = -1
        SoundForwardAndDownWithDown2 = -1
        SoundForwardAndDownWithMinus2 = -1
        SoundForwardAndDownWithHome2 = -1
        SoundForwardAndDownWithPlus2 = -1
        SoundNunchuk2 = -1
        SoundNunchukWithC2 = -1
        SoundNunchukWithZ2 = -1

    End Sub

    Private Sub SetToolTips()

        'Set up some tips to help people figure out what's going on

        tt = New ToolTip()

        'tt.SetToolTip(cmbPreset, "Select a preset or type in the name of a new preset.")
        'tt.SetToolTip(btnSavePreset, "Save over an old preset, or create a new one.")

        'tt.SetToolTip(btnLoop1, "Click here to add a sound to the 1 button.")
        'tt.SetToolTip(btnLoop2, "Click here to add a sound to the 2 button.")

        tt.SetToolTip(tb1MinX, "Change the threshold to fit your style.")
        tt.SetToolTip(tb1MaxZ, "Change the threshold to fit your style.")
        tt.SetToolTip(tb1MinY, "Change the threshold to fit your style.")

        tt.SetToolTip(btnSetSoundForwardAndDownWithLeft1, "Add a file for the down swing with the d-pad pressed to the left.")
        tt.SetToolTip(btnSetSoundForwardAndDownWithUp1, "Add a file for the down swing with the d-pad pressed to the up.")
        tt.SetToolTip(btnSetSoundForwardAndDownWithRight1, "Add a file for the down swing with the d-pad pressed to the right.")
        tt.SetToolTip(btnSetSoundForwardAndDownWithDown1, "Add a file for the down swing with the d-pad pressed to the down.")

        tt.Active = True
    End Sub

    Public Sub SetProgressBarValue(ByRef pProgessBar As ProgressBar, ByVal value As Integer)

        If pProgessBar.InvokeRequired Then

            Dim f As SetInt = New SetInt(AddressOf SetProgressBarValue)

            pProgessBar.Invoke(f, New Object() {pProgessBar, value})

        Else

            pProgessBar.Value = value

        End If

    End Sub

    Public Sub SetLabelText(ByRef pLabel As Label, ByVal text As String)

        If pLabel.InvokeRequired Then

            Dim f As SetText = New SetText(AddressOf SetLabelText)

            pLabel.Invoke(f, New Object() {pLabel, text})

        Else

            pLabel.Text = text

        End If

    End Sub

    Private Sub SetUpOutputDevice()

        Dim deviceList As New List(Of String)
        deviceList = soundbank.getDeviceList()
        cmbOutput.Items.Clear()
        For Each dev As String In deviceList
            cmbOutput.Items.Add(dev)
        Next
        cmbOutput.SelectedIndex = 0

    End Sub

    ''' <summary>
    ''' When the user changes the output device
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub cmbOutput_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbOutput.SelectedIndexChanged

        soundbank.setOutputDevice(cmbOutput.Text, Me)

    End Sub

    Private Sub tmrFade_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrFade.Tick

        Me.Opacity = (Fade * 0.01)

        Fade += 1

        If Fade = 100 Then
            tmrFade.Enabled = False
            Me.Opacity = 1.0
            Start()
            Me.Enabled = True
            MessageBox.Show("If You Want To Play With The Nunchuk" & vbCrLf & "Plug It Into The Wiimote Now", "Nunchuk Connection", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If

    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click

        'Close The Application
        Me.Dispose()

        FormTestConnection.Dispose()

    End Sub

    Private Sub CreateNewPresetFileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CreateNewPresetFileToolStripMenuItem.Click

        Dim response As String = InputBox("Please Enter A New Preset Name", "Create New Preset File", "")

        If response <> vbNullString Then

            cmbPreset.Items.Add(response)

            My.Computer.FileSystem.WriteAllText(Application.StartupPath & response & ".preset", String.Empty, False)

            SavePreset(response)

            MessageBox.Show("New Preset Successfully Created", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Information)

        End If

    End Sub

    Private Sub frmWiiDrums_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing

        TurnOffWiimoteLEDs()

        If MetronomeToolStripMenuItem.Text = "Close Metronome" Then

            FormMetronome.Dispose()

        End If

        FormTestConnection.Close()

        FormTestConnection.Dispose()

    End Sub

    Private Sub TurnOffWiimoteLEDs()

        If Wiimote_Collection.Count = 1 Then

            wiimote1.SetLEDs(False, False, False, False)

        Else

            wiimote1.SetLEDs(False, False, False, False)
            wiimote2.SetLEDs(False, False, False, False)

        End If

    End Sub

    Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click

        Dim AboutForm As New frmAbout()
        AboutForm.Show()

    End Sub

    Private Sub DeletePresetFileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeletePresetFileToolStripMenuItem.Click

        DeletePreset()

    End Sub

    Private Sub AudioControlPanelToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AudioControlPanelToolStripMenuItem.Click

        'Open Audio Control Panel
        Call Shell("rundll32.exe shell32.dll,Control_RunDLL mmsys.cpl,,0")

    End Sub

    Private Sub WwwsoundsnapcomToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WwwsoundsnapcomToolStripMenuItem.Click

        Dim lblSoundsLink As New LinkLabel()
        lblSoundsLink.Tag = "http://www.soundsnap.com"
        System.Diagnostics.Process.Start(lblSoundsLink.Tag.ToString())

    End Sub

    Private Sub StartUpSoundToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartUpSoundToolStripMenuItem.Click

        If StartUpSoundToolStripMenuItem.Checked Then
            StartUpSoundToolStripMenuItem.Checked = False
        Else
            StartUpSoundToolStripMenuItem.Checked = True
        End If

        SaveSettings()

    End Sub

    Private Sub FileToolStripMenuItem_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileToolStripMenuItem.MouseEnter
        FileToolStripMenuItem.ForeColor = Color.Black
    End Sub

    Private Sub FileToolStripMenuItem_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileToolStripMenuItem.MouseLeave
        FileToolStripMenuItem.ForeColor = Color.White
    End Sub

    Private Sub HelpToolStripMenuItem_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HelpToolStripMenuItem.MouseEnter
        HelpToolStripMenuItem.ForeColor = Color.Black
    End Sub

    Private Sub HelpToolStripMenuItem_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HelpToolStripMenuItem.MouseLeave
        HelpToolStripMenuItem.ForeColor = Color.White
    End Sub

    Private Sub SettingsToolStripMenuItem_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SettingsToolStripMenuItem.MouseEnter
        SettingsToolStripMenuItem.ForeColor = Color.Black
    End Sub

    Private Sub SettingsToolStripMenuItem_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SettingsToolStripMenuItem.MouseLeave
        SettingsToolStripMenuItem.ForeColor = Color.White
    End Sub

    Private Sub buttonSoundfile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonSoundfile.Click

        btnStartRecording.Enabled = True

        OnCreateSoundFile()

    End Sub

    Private Sub btnStartRecording_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartRecording.Click

        btnStopRecording.Enabled = True

        btnStartRecording.Enabled = False

        tmrStartStopRecordImage.Enabled = True

        Recording = True

        StartOrStopRecord(Recording)

        'Dim objRecordSound As New RecordSound(Me)

    End Sub

    Private Sub btnStopRecording_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStopRecording.Click

        btnStopRecording.Enabled = False

        tmrStartStopRecordImage.Enabled = False

        pbStartStopRecord.Image = My.Resources.Green

        Recording = False

        StartOrStopRecord(Recording)

    End Sub

    Private Sub comboboxCaptureDeviceCombo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles comboboxCaptureDeviceCombo.SelectedIndexChanged

        If comboboxCaptureDeviceCombo.Items.Count > 0 Then

            CaptureDeviceGuid = devices(comboboxCaptureDeviceCombo.SelectedIndex).DriverGuid

            ScanAvailableInputFormats()

            FillFormatListBox()

        End If

    End Sub

    Private Sub lbFormatsInputListbox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboFormatsInputListbox.SelectedIndexChanged

        FormatsOK()

    End Sub

    Private Sub btnViewDirectory_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenDirectory.Click

        If tvViewDirectory.Nodes.Count > 0 Then
            tvViewDirectory.Nodes.Clear()
        End If

        tvViewDirectory.Enabled = True
        FolderBrowserDialog1.Description = "Select The Folder Where You Saved Your Wii Play The Drums Session"
        If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
            SelectedDirectoryPath = FolderBrowserDialog1.SelectedPath
            Dim dirinfo As New DirectoryInfo(SelectedDirectoryPath)
            Dim mainnode As New TreeNode(SelectedDirectoryPath, 0, 0)
            tvViewDirectory.Nodes.Add(mainnode)
            For Each file As FileInfo In dirinfo.GetFiles("*.wav")
                If file.Exists() Then
                    Try
                        Dim tn As New TreeNode(file.Name, 1, 1)
                        tn = mainnode.Nodes.Add(file.Name)
                        tn.SelectedImageIndex = 1
                    Catch exp As Exception
                        MessageBox.Show(exp.Message)
                    End Try
                End If
            Next
            mainnode.Expand()
        End If

    End Sub

    Private Sub btnPlaySelectedWaveFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlaySelectedWaveFile.Click

        If Not tvViewDirectory.Enabled Then
            Exit Sub
        End If

        If File.Exists(SelectedDirectoryPath & "\" & tvViewDirectory.SelectedNode.Text) Then
            My.Computer.Audio.Play(SelectedDirectoryPath & "\" & tvViewDirectory.SelectedNode.Text)
        Else
            MessageBox.Show("Cannot Play Selected File", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If

    End Sub

    Private Sub btnStopPlayingSelectedWaveFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStopPlayingSelectedWaveFile.Click

        My.Computer.Audio.Stop()

    End Sub

    Private Sub tmrStartStopRecordImage_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrStartStopRecordImage.Tick

        If Me.imageswitch = 0 Then

            pbStartStopRecord.Image = My.Resources.Red

            imageswitch = 1

        Else

            pbStartStopRecord.Image = My.Resources.Green

            imageswitch = 0

        End If

    End Sub

    Private Sub MetronomeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MetronomeToolStripMenuItem.Click

        If MetronomeToolStripMenuItem.Text = "Open Metronome" Then

            FormMetronome = New frmMetronome
            FormMetronome.Show()
            MetronomeToolStripMenuItem.Text = "Close Metronome"

        Else

            MetronomeToolStripMenuItem.Text = "Open Metronome"
            FormMetronome.Dispose()

        End If

    End Sub

End Class

